fix: return assignee roster within the lock (NQ-69-01)

This commit is contained in:
2026-09-17 09:17:35 -04:00
parent 90671815ee
commit 58f5ddab72
3 changed files with 68 additions and 6 deletions
+7 -2
View File
@@ -962,14 +962,18 @@ class QuestDefinitionsDao:
async def add_assignee(
self, definition_id: int, child_id: int
) -> None:
) -> list[ChildRecord]:
"""Assign ``child_id`` to the definition (idempotent).
Validates the assignee inside the same serialized transaction
as the INSERT (existing and active AT ASSIGNMENT TIME), so a
child deactivated concurrently cannot become an assignee.
Assigning an already-assigned child is a no-op, mirroring the
composite primary key's storage-level guarantee. Changes
composite primary key's storage-level guarantee. Returns the
definition's assignees read back INSIDE the same transaction
that performed the write, so the returned roster is a
consistent post-assignment snapshot — a concurrent assign or
unassign cannot race it after the write commits. Changes
future instances only: already-generated instances and
completion history are never rewritten here.
"""
@@ -990,6 +994,7 @@ class QuestDefinitionsDao:
"ON CONFLICT (definition_id, child_id) DO NOTHING",
(definition_id, child_id),
)
return await self.list_assignees(definition_id)
async def remove_assignee(
self, definition_id: int, child_id: int
@@ -348,8 +348,9 @@ async def assign_child(
active/exists check inside its transaction, and also confirms the
definition exists. Assigning an already-assigned child is a no-op
(no duplicate row). Returns the definition's assignees read back
through the DAO, a consistent post-assignment roster. Raises
ValueError on any rejected argument. Only the
inside the DAO's same transaction, a consistent post-assignment
roster (a concurrent assign/unassign cannot race it after the
write). Raises ValueError on any rejected argument. Only the
``quest_definition_assignees`` link is written; existing instances
and completion history are never touched.
"""
@@ -357,7 +358,7 @@ async def assign_child(
_validate_child_id(child_id)
dao = QuestDefinitionsDao(database)
try:
await dao.add_assignee(definition_id, child_id)
return await dao.add_assignee(definition_id, child_id)
except ValueError as error:
# The DAO names only the child/definition; re-raise so the
# public contract names the field the caller actually passed.
@@ -367,7 +368,6 @@ async def assign_child(
if message.startswith("quest definition "):
raise ValueError(f"definition_id: {message}") from error
raise
return await dao.list_assignees(definition_id)
async def unassign_child(