fix: coerce audit_log pkey unique violations to non-fatal errors in *_and_log (OPS-4601)#64
Closed
palantir-valiot[bot] wants to merge 1 commit into
Closed
Conversation
…_and_log paths (OPS-4601) - Add unique_constraint(:id, name: "<table>_pkey") at the two repo.insert sites (log_changes and log_changes_alone) so Ecto turns ConstraintError into changeset errors. - TDD: added integration test that forces pkey collision via sequence reset + blocker row; asserts main update commits and error is logged. - Bump 1.0.3 -> 1.0.4; update CHANGELOG. - Also upgraded benchee/credo within ranges (per workflow). - mix format applied. Closes OPS-4601
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
Add
Changeset.unique_constraint(:id, name: "<table>_pkey")(using the runtime-configurable audit log table name) before the two barerepo.insert/1calls that write audit entries insidelog_changes/5andlog_changes_alone/6. This turns anEcto.ConstraintErroronaudit_logs_pkey(or the configured table) into a normal{:error, changeset}that is already handled as a non-fatal audit-log failure (logged + swallowed, main operation still commits). Includes a TDD integration test that forces a pkey collision via sequence reset + blocker row and asserts the caller's update succeeds while the colliding audit row is not written.Files changed:
lib/ecto_trail/ecto_trail.ex(the two insert sites + module attribute for table name)test/unit/ecto_trail_test.exs(new test in theupdate_and_log/3describe)mix.exs(1.0.3 → 1.0.4)CHANGELOG.md(entry for 1.0.4)mix.lock(benchee 1.5.0→1.5.1, credo 1.7.18→1.7.19 and transitive, per workflow)Why
OPS-4601: production
Ecto.ConstraintErroronaudit_logs_pkeyduringEctoTrail.update_and_log(stack:ecto_trail.ex:435inlog_changes/5,ecto_trail.ex:315in theupdate_and_logtransaction fn). The audit log insert had nounique_constraintdeclaration for the (configurable) pkey, so Postgres unique violations escaped as hard exceptions instead of being treated like other log failures. 10+ similar errors queued across services. This is an explicit code bug in the first-party library.Test plan
mix format(clean)mix compile)git diff(no debug prints, no scope creep, only the minimal unique_constraint + test + housekeeping)mix hex.outdatedcheckedmix test— cannot run to completion in this environment (no Postgres listener on 5432; test helper does full migration + sandbox). The new test and all prior tests will be exercised by CI on this PR. The change only affects the error-handling path aroundrepo.insertfor the Changelog schema.pull_request_template.md.Closes OPS-4601