fix(audit): correct SQL placeholder numbering in audit-log list (PMS-178) #144
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-178-audit-list-placeholders"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Fixes PMS-178:
GET /api/v1/audit-logreturned HTTP 500 whenever any filter (entity_type,action,user_id,from,to) was supplied.Cause
In
AuditService::listthe dynamic filter conditions were numbered starting at$3, colliding with the fixedLIMIT $2 OFFSET $3, and the bind order (tenant, limit, offset, filters…) did not match the placeholder indices, so the code bound more values than the prepared statement declared and Postgres rejected it. The samewhere_clausewas also shared by the data query (binds limit/offset) and the count query (does not), so no single placeholder scheme was correct for both. No-filter reads happened to work, hiding it until theRequireAdminaudit read was first exercised with filters by the PMS-155 E2E suite (GET /audit-log?entity_type=companies&action=create -> 500).Fix
$1.LIMIT/OFFSETas the last two placeholders of the data query and bind them last; the count query binds neither.where_clauselines up.Tests
tests/audit_list.rs: a seeded super-admin issuesGET /api/v1/audit-logacross several filter combinations (none, entity_type+action, user_id, from+to+entity_type+action) and asserts each returns 200. An empty result set is still a 200; the bug was at the query layer.cargo check --all-targets,clippy --all-targets,fmt --checkall clean.Note
Once this deploys to staging, the PMS-155 E2E audit spec goes green. The remaining
[teardown] DELETE …companies… -> 500line in that run is a separate bug, PMS-170 (unguarded FK -> 500 on company delete), not addressed here.🤖 Generated with Claude Code