fix: handle audit_log pkey unique constraint to prevent Ecto.ConstraintError in *_and_log (OPS-4563)#25
Closed
palantir-valiot[bot] wants to merge 1 commit into
Closed
Conversation
…ntError in *_and_log (OPS-4563)
Member
|
Closing as a duplicate of #24 — all of these PRs fix the same bug: |
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
Declare the
audit_log_pkey(or${table}_pkey) unique constraint on the Changelog changeset and include:idin the cast. This converts the rawEcto.ConstraintErrorraised fromrepo.insert/1insidelog_changes/5(called byupdate_and_log/4and friends inside a transaction) into a regular{:error, changeset}that is already logged and swallowed (existing policy). No behavior change for happy path or other errors.Files:
lib/ecto_trail/ecto_trail.ex:578(changelog_changeset)test/unit/ecto_trail_test.exs(new TDD regression test underupdate_and_log/3)mix.exs(1.0.4),CHANGELOG.md,mix.lock(within-range dep bumps for baseline)Why
OPS-4563 (Linear). Stack trace:
Triage decision: NOTIFY+FIX (high, code_bug). First-party package; must be fixed regardless of frequency.
Assumptions
:table_name(default "audit_log"), so the constraint name is computed the same way the migration uses it.{:ok, reason}or{:ok, operation}path is taken). We preserve that contract.Test plan
insert!+setvalonaudit_log_id_seq, then callsupdate_and_log; asserts success and no crash). The test reproduces the exact production failure mode.mix format --check-formattedmix compile(clean; only pre-existing warning unrelated to this change)mix hex.outdated+ upgradedbenchee/credo(within allowed ranges) + updatedmix.lockCHANGELOG.mdconcise entry + semver patch bumpgit push-safeonpalantir/OPS-4563-handle-audit-pkey-constraintmix test(environment has no running Postgres; the new test path will be exercised by CI on PR and the existing suite already covers update_and_log success/error cases)Closes OPS-4563