Skip to content

fix(displayId): TAMOC-401: Hotfix 2.45: Corrupted snapshot records changelog value created in resolveDuplicatedPatientIds hook#9261

Open
dannash100 wants to merge 4 commits intorelease/2.45from
fix/remove-duplicate-corrupt-changelog-data
Open

fix(displayId): TAMOC-401: Hotfix 2.45: Corrupted snapshot records changelog value created in resolveDuplicatedPatientIds hook#9261
dannash100 wants to merge 4 commits intorelease/2.45from
fix/remove-duplicate-corrupt-changelog-data

Conversation

@dannash100
Copy link
Contributor

@dannash100 dannash100 commented Mar 2, 2026

Changes

Root cause: resolveDuplicatedPatientDisplayIds spreads the full snapshot record (including changelogRecords) into its update objects. The pg driver's parsed json value for changelog_records doesn't survive the round-trip through write-back and re-read as a proper JS Array, so extractChangelogFromSnapshotRecords blows up trying to spread it.

resolveDuplicatedPatientDisplayIds.ts — delete changelogRecords from update objects so it's excluded from the UPDATE query and the DB column keeps its original value.

resolveDuplicatedPatientDisplayIds was the only hook that spread ...c from an existing snapshot record into an update, carrying changelogRecords along for the ride. No other hook has this problem.

Deploys

  • Deploy to Tamanu Internal

Tests

  • Run E2E Tests

Review Hero

  • Run Review Hero
  • Auto-fix review suggestions Wait for Review Hero to finish, resolve any comments you disagree with or want to fix manually, then check this to auto-fix the rest.
  • Auto-fix CI failures Check this to auto-fix lint errors, test failures, and other CI issues.

Remember to...

  • ...write or update tests
  • ...add UI screenshots and testing notes to the Linear issue
  • ...add any manual upgrade steps to the Linear issue
  • ...update the config reference, settings reference, or any relevant runbook(s)
  • ...call out additions or changes to config files for the deployment team to take note of

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical data corruption issue that occurred during the patient display ID deduplication process. The problem stemmed from changelogRecords being included in database update operations, leading to data integrity problems upon re-reading due to how the pg driver handles JSON values. The fix ensures that these records are correctly excluded from updates, thereby preventing corruption and maintaining data consistency.

Highlights

  • Data Corruption Fix: Resolved an issue where resolveDuplicatedPatientDisplayIds caused corrupted snapshot records by inadvertently including changelogRecords in update objects, which did not survive the database round-trip correctly.
  • Changelog Records Exclusion: Modified the update logic within resolveDuplicatedPatientDisplayIds.ts to explicitly delete changelogRecords from patient snapshot update objects, ensuring they are excluded from the UPDATE query and preserving their original database value.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/database/src/sync/resolveDuplicatedPatientDisplayIds.ts
    • Excluded changelogRecords from patient snapshot update objects to prevent data corruption during database writes.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request provides a hotfix for a data corruption issue where changelogRecords were being improperly handled during a database update. The fix correctly removes this property before the update query. My review includes a suggestion to refactor the implementation to be more declarative and avoid object mutation, which can improve code clarity and maintainability.

Comment on lines +51 to +58
.map((c) => {
const updated = {
...c,
data: { ...c.data, displayId: `${c.data.displayId}_duplicate_2` },
};
delete (updated as any).changelogRecords;
return updated;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the current implementation is correct, you can achieve the same result more declaratively by using object destructuring to omit the changelogRecords property. This avoids mutating the updated object with delete and is generally considered a cleaner, more functional approach.

      .map((c) => {
        const { changelogRecords, ...rest } = c as any;
        return {
          ...rest,
          data: { ...c.data, displayId: `${c.data.displayId}_duplicate_2` },
        };
      });

@dannash100
Copy link
Contributor Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@dannash100 dannash100 changed the title fix(displayId): Hotfix 2.45: Corrupted snapshot record after resolveDuplicatedPatientIds fix(displayId): TAMOC-401: Hotfix 2.45: Corrupted snapshot records changelog value created in resolveDuplicatedPatientIds hook Mar 3, 2026
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