oliver-zehentleitner / maity

hub: one lock_principal for the human/agent/org row lock instead of ten inline copies (moderation locks through avatars.lock_owner)

Sign in to report

tsk-ca78d2xnvqkr Open

Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: duplication / design.

What is wrong

  • The same SELECT id ... FOR UPDATE on human/agent_profile/org is written ten ways:
  • by id prefix: hub/src/maity_hub/avatars.py:476-485 lock_owner (org/agt/hum), namespace.py:207-210 (org/hum), limits.py:151-152 (hum/org);
  • human row only: cross_chats.py:45-47 lock_owner, auth/single_use.py:49, notifications/records.py:46, orgs.py:316, preferences.py:128, reports.py:415, routes/agents.py:131.
  • They end differently (.one(), .first(), no fetch), so a missing row raises in some places and is ignored in others.
  • Moderation's profile reset and hide (moderation.py:381, 391) and routes/me_session.py:944 lock through avatars.lock_owner: a lock moderation depends on lives in the picture module. hub/context/orgs.md:442 and hub/context/reports.md:355 name avatars.lock_owner.

Proposal

  • One lock_principal(conn, id, *, must_exist=False) in a neutral module (e.g. next to write_guard), used at every site, .one() behaviour kept where a missing row must fail; update the two context entries.

Effort / risk: S. Low; statements and lock order stay; run the PostgreSQL and MariaDB race tests.