fix: declare unique_constraint/3 on audit_log pkey in update_and_log / log paths (OPS-4604)#62
Closed
palantir-valiot[bot] wants to merge 1 commit into
Closed
Conversation
…og paths to prevent Ecto.ConstraintError on collision (OPS-4604)
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.
Description
update_and_log(and the sharedlog_changes/log_changes_alonehelpers used by all*_and_logandlog*entrypoints) performed a rawrepo.insert/1of anaudit_log(or${table_name}) row without declaring aunique_constraint/3for the primary key. On pkey collisions (sequence rewind, concurrent writers, or test fixtures that reset sequences) this surfaces as an unhandledEcto.ConstraintErrorinstead of a changeset error:Summary of change
Changeset.unique_constraint(:id, name: audit_log_pkey_constraint())immediately before the tworepo.insert/1calls that create audit rows (log_changes/5andlog_changes_alone/6).audit_log_pkey_constraint/0that computes the constraint name from the configured table name (defaults to"audit_log_pkey"; supports the:table_nameconfig override).describe "update_and_log/3"that forces a pkey collision by rewinding the sequence and asserts thatupdate_and_logstill succeeds (the existing error path already swallows the resulting changeset error and only logs it).1.0.3→1.0.4and added a concise changelog entry.Files changed:
lib/ecto_trail/ecto_trail.extest/unit/ecto_trail_test.exsmix.exsCHANGELOG.mdWhy
See Linear OPS-4604. The triage diagnosis was definitive: the call stack points straight at the two blind inserts in first-party
ecto_trail. The fix is the exact mitigation the error message itself recommends (unique_constraint/3on the changeset with the constraint:name).Type of change
How Has This Been Tested?
mix format --check-formatted(clean)mix compile(clean, only pre-existing redundant-clause warning)update_and_log -> log_changes -> insertpath that was raising.ALTER SEQUENCE … RESTART WITHand asserts the public API does not raiseEcto.ConstraintError.mix testandmix credo --strictare the repo's prescribed checks (per.travis.yml/ historical CI); both would be run by CI on the PR. The agent environment has no reachable Postgres, so full test execution is blocked by DB connectivity only (expected and non-blocking for this change).Test Configuration (agent pod):
Checklist:
mix format)Closes OPS-4604