Skip to content
Sarj Code Standards

store-insert-requires-explicit-conflict-policy

Declare SQL conflict behavior for store INSERT statements, including fixture writes.

Why

A visible SQL conflict policy makes retry and fixture behavior reviewable at the write boundary. Plain INSERT can intentionally reject duplicates; record that contract with an exact rule exception.

Fix

Declare the intended ON CONFLICT behavior, or add an exact SARJ547 exception explaining why duplicate rejection, append-only insertion, or deliberately invalid fixture data is required. Preserve uniqueness, errors, return shape and transaction behavior; DO NOTHING is not an automatic replacement.

Examples

Before — flagged Fixture inserts need an explicit duplicate decision
tests/fixtures/rows.py
from psycopg import AsyncCursor
class RowsFixture:
def __init__(self, cursor: AsyncCursor):
self.cursor = cursor
async def insert(self):
await self.cursor.execute("INSERT INTO item(id) VALUES(%s)", (1,))
After — preferred A fixture declares its duplicate behavior
tests/fixtures/rows.py
from psycopg import AsyncCursor
class RowsFixture:
def __init__(self, cursor: AsyncCursor):
self.cursor = cursor
async def insert(self):
await self.cursor.execute(
"INSERT INTO item(id) VALUES(%s) ON CONFLICT DO NOTHING", (1,)
)