You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
db: bulk-DML audit prefetch drops with_loader_criteria and records rows the statement did not touch #810
Bulk-DML auditing prefetches the affected IDs with a SELECT rebuilt from stmt.whereclause. That SELECT drops statement options such as with_loader_criteria, which SQLAlchemy does apply to the UPDATE/DELETE itself. So the audit log can record bulk_updated/bulk_deleted entries for rows the statement never touched. This contradicts docs/modules/audit_log.md:40.
With two rows (value 1 and value 2), run update(AuditTestItem).options(with_loader_criteria(AuditTestItem, AuditTestItem.value == 2)).values(name="changed"). The rowcount is 1, but audit records are written for both IDs.
Suggested fix
Build the prefetch SELECT with the statement's _with_options / loader criteria carried over, or use RETURNING where the dialect supports it.
Found in a full review of simple_module_db (main @ 7a5c860).
Activity
fix(db,audit_log): bulk audit prefetch keeps loader criteria; ORM res…
antosubash commentedon Nov 4, 2026
Fixed in #821 (squash-merged as 0fcd877).