Skip to content
Sarj Code Standards

store-mutation-command-fanout

Review per-field store mutations beside an existing model write command.

Why

Per-field mutation entry points beside a model upsert can scatter write validation and concurrency policy. A smaller typed command surface makes those contracts easier to review together.

Fix

Review whether these methods can share a typed mutation command or internal write implementation. Preserve update-only and missing-row behavior, authorization, omission versus null, and guarded transitions. Do not replace a conditional UPDATE with an insert-capable upsert; model distinct transitions explicitly when they must stay separate.

Examples

Before — flagged Review a separate guarded setter
app/item_store.py
from psycopg import AsyncCursor
class ItemStore:
def __init__(self, cursor: AsyncCursor):
self.cursor = cursor
async def upsert(self, item):
await self.cursor.execute(
"INSERT INTO item(id, name) VALUES(%s, %s) ON CONFLICT(id) DO UPDATE SET name=EXCLUDED.name",
(item.id, item.name),
)
async def set_name_before_start(self, key, name):
await self.cursor.execute(
"UPDATE item SET name=%s WHERE id=%s AND started_at IS NULL", (name, key)
)
After — preferred Different relation ownership is preserved
app/item_store.py
from psycopg import AsyncCursor
class ItemStore:
def __init__(self, cursor: AsyncCursor):
self.cursor = cursor
async def upsert(self, item):
await self.cursor.execute(
"INSERT INTO item(id, name) VALUES(%s, %s) ON CONFLICT(id) DO UPDATE SET name=EXCLUDED.name",
(item.id, item.name),
)
async def set_name_before_start(self, key, name):
await self.cursor.execute(
"UPDATE other SET name=%s WHERE id=%s AND started_at IS NULL", (name, key)
)