diff --git a/src/scribe/services/embeddings.py b/src/scribe/services/embeddings.py index a905b1e..bf66e49 100644 --- a/src/scribe/services/embeddings.py +++ b/src/scribe/services/embeddings.py @@ -374,7 +374,10 @@ async def _claim_parent_row(session, id_column, row_id: int, label: str) -> bool held = (await session.execute( select(id_column) .where(id_column == row_id) - .with_for_update(key_share=True, nowait=True) + # BOTH flags: SQLAlchemy spells the four Postgres row locks as a + # read/key_share pair, and key_share alone is FOR NO KEY UPDATE — + # which would make two refreshes of one record fight each other. + .with_for_update(read=True, key_share=True, nowait=True) )).scalar_one_or_none() except Exception: # LockNotAvailable: this record is being deleted right now. Not an