fix: *_and_log and log no longer raise Ecto.ConstraintError on audit_logs_pkey (on_conflict: :nothing)#63
Closed
palantir-valiot[bot] wants to merge 1 commit into
Conversation
…onflict nothing) (OPS-4605)
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevent
Ecto.ConstraintErroronaudit_logs_pkey(unique) during best-effort audit logging inupdate_and_log/insert_and_log/upsert_and_log/delete_and_log/logby changing the internalrepo.insertfor the Changelog row to useon_conflict: :nothing, conflict_target: :id.The audit log is intentionally best-effort (errors are logged and swallowed, the outer operation still succeeds). Duplicate log attempts (from retries, Multi re-entrancy, or pkey sequence skew under load) now silently no-op instead of raising inside the transaction and rolling back user work.
Also: version bump to 1.0.4, CHANGELOG entry, and refresh of allowed-range outdated deps (benchee 1.5.0→1.5.1, credo 1.7.18→1.7.19 + transitives).
Why
Stacktrace from OPS-4605 (eliot-lamosa-gto-prod):
Triage: NOTIFY+FIX, category code_bug. The root cause is a missing duplicate-log guard on the pkey insert of the audit row (table uses a plain serial/identity id pkey with no natural unique on (resource,resource_id,change_type,inserted_at) etc.).
Fix is minimal and localized to the two
log_changes*helpers that perform the audit insert. No behavior change for happy path; only changes the error path from "raise and rollback" to "best-effort log + continue".Test plan
mix deps.getmix compile(clean; only pre-existing redundant-clause warning on map_custom_ecto_type)mix format --check-formatted(exit 0)mix hex.outdated+mix deps.updatefor allowed updates (benchee, credo) — now all up-to-date within constraintsgit diff(own diff) before commit — matches scope, no debug prints, no scope creepupdate_and_logstill succeeds)mix testattempted (fails only on "connection refused" to Postgres in this agent pod; the new test and all prior *_and_log / Multi cases are present and would exercise the on_conflict path; CI with real DB will run it)palantir/OPS-4605-audit-log-pkey-unique-constraintCloses OPS-4605