Python · correctness
store-insert-requires-on-conflict
python:store-insert-requires-on-conflict Embedded SQL inserts in store code must handle conflicts explicitly.
- Code
- SARJ018
- Default
- error
- Fix
- none
- Languages
- python
Why
A replayed write without conflict handling can fail or create duplicate state.
Fix
Use `ON CONFLICT`, `ON DUPLICATE KEY`, or SQLite `OR IGNORE`/`OR REPLACE` as appropriate.
Before / after
Executed by this rule’s unit tests.
Before
Store insert without conflict handling
QUERY = "INSERT INTO task (id) VALUES (%s)"
After
Store insert with conflict handling
QUERY = "INSERT INTO task (id) VALUES (%s) ON CONFLICT DO NOTHING"
Limits
- Only SQL string literals in recognized store modules are analyzed.
- A deliberate non-idempotent insert requires a local SARJ018 suppression.