Skip to content

NIAD-3273 Fix DuplicatePrimaryKeyError on MHS Outbound retry by using upsert instead of insert#439

Open
chiaramapellimt wants to merge 1 commit into
mainfrom
NIAD-3273
Open

NIAD-3273 Fix DuplicatePrimaryKeyError on MHS Outbound retry by using upsert instead of insert#439
chiaramapellimt wants to merge 1 commit into
mainfrom
NIAD-3273

Conversation

@chiaramapellimt
Copy link
Copy Markdown
Contributor

@chiaramapellimt chiaramapellimt commented May 18, 2026

What

Replace insert_one with find_one_and_replace using upsert=True in MongoPersistenceAdaptor.add. Updated the corresponding test to reflect the new behaviour.

Relates ticket: https://nhse-dsic.atlassian.net/browse/NIAD-3273

Why

When an MHS Outbound request failed with a 500, the record was already written to MongoDB. Retrying with the same Message ID would then fail with a DuplicatePrimaryKeyError because insert_one does not allow duplicate keys. Using upsert means the retry will overwrite the existing record instead of erroring, allowing the request to be resent successfully.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Internal change (non-breaking change with no effect on the functionality affecting end users)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the Changelog with details of my change in the UNRELEASED section if this change will affect end users

… upsert instead of insert

Fix libxslt1-dev version pin across Dockerfiles

NIAD-3273 Fix DuplicatePrimaryKeyError on MHS Outbound retry by using upsert instead of insert
@chiaramapellimt chiaramapellimt marked this pull request as ready for review May 18, 2026 14:54
@chiaramapellimt chiaramapellimt requested a review from a team as a code owner May 18, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant