Skip to content

Add snapshot unique_key hint for duplicate row errors#12983

Open
desusaiteja wants to merge 2 commits into
dbt-labs:main_backupfrom
desusaiteja:issue-10864-snapshot-unique-key-hint
Open

Add snapshot unique_key hint for duplicate row errors#12983
desusaiteja wants to merge 2 commits into
dbt-labs:main_backupfrom
desusaiteja:issue-10864-snapshot-unique-key-hint

Conversation

@desusaiteja

Copy link
Copy Markdown

Resolves #10864

Problem

When a snapshot unique_key is not actually unique, some adapters return a generic Duplicate row detected during DML action error. The existing message does not point users toward the likely root cause, which makes a straightforward snapshot configuration issue harder to diagnose.

Solution

Append a snapshot-specific hint when snapshot execution surfaces the duplicate-row DML error. The new hint points users to the likely problem: the configured unique_key is not unique in the snapshot query.

This PR adds:

  • A small SnapshotRunner.handle_exception override that appends the hint only for the duplicate-row DML error message.
  • Unit coverage for the string helper behavior.
  • A mocked runner-level test that simulates the adapter-specific error path and verifies the hint is added through SnapshotRunner.handle_exception.

I also ran the change in development and verified the local Postgres path. Postgres did not naturally reproduce this adapter-specific error, so the adapter-specific branch is covered via the mocked runner test.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@desusaiteja desusaiteja requested a review from a team as a code owner May 19, 2026 03:24
@cla-bot

cla-bot Bot commented May 19, 2026

Copy link
Copy Markdown

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @desusaiteja

@github-actions github-actions Bot added the community This PR is from a community member label May 19, 2026
codescene-delta-analysis[bot]

This comment was marked as outdated.

@desusaiteja desusaiteja force-pushed the issue-10864-snapshot-unique-key-hint branch from 03f5356 to f23c06c Compare May 19, 2026 03:54
@cla-bot cla-bot Bot added the cla:yes label May 19, 2026
codescene-delta-analysis[bot]

This comment was marked as outdated.

…apshot-unique-key-hint

# Conflicts:
#	core/dbt/task/snapshot.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:yes community This PR is from a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messaging for snapshots: unique-key error

1 participant