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)
tsk-ca78d2xnvqkr Open
Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: duplication / design.
What is wrong
- The same
SELECT id ... FOR UPDATEonhuman/agent_profile/orgis written ten ways: - by id prefix:
hub/src/maity_hub/avatars.py:476-485lock_owner(org/agt/hum),namespace.py:207-210(org/hum),limits.py:151-152(hum/org); - human row only:
cross_chats.py:45-47lock_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) androutes/me_session.py:944lock throughavatars.lock_owner: a lock moderation depends on lives in the picture module.hub/context/orgs.md:442andhub/context/reports.md:355nameavatars.lock_owner.
Proposal
- One
lock_principal(conn, id, *, must_exist=False)in a neutral module (e.g. next towrite_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.