Skip to content

fix(#821): ignore deleted primary-contact ref in move-contacts - #824

Open
Hendrixx-RE wants to merge 3 commits into
medic:mainfrom
Hendrixx-RE:fix(#821)ignore-dangling-primary-contact
Open

fix(#821): ignore deleted primary-contact ref in move-contacts#824
Hendrixx-RE wants to merge 3 commits into
medic:mainfrom
Hendrixx-RE:fix(#821)ignore-dangling-primary-contact

Conversation

@Hendrixx-RE

Copy link
Copy Markdown
Contributor

Description

Wrap the db.get(sourcePrimaryContactId) call in a try/catch. A 404 (deleted or missing doc) is treated as "no primary contact" — a WARN is logged and the operation continues. Any other error is re-thrown unchanged.

medic/cht-conf #821

Code review items

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or integration tests where appropriate
  • Backwards compatible: Works with existing data and configuration. Any breaking changes documented in the release notes.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@binokaryg
binokaryg self-requested a review June 2, 2026 06:10
@binokaryg binokaryg closed this Jun 2, 2026
@binokaryg binokaryg reopened this Jun 2, 2026

@binokaryg binokaryg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tests are failing because of max-len. Please fix it.
There is one more inline comment about a test gap.

Comment thread src/lib/hierarchy-operations/lineage-constraints.js Outdated
Comment thread test/lib/hierarchy-operations/lineage-constraints.spec.js
@andrablaj
andrablaj requested a review from binokaryg June 30, 2026 16:13

@binokaryg binokaryg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One small change request regarding stub restore. Apart from that, I think it's good.

});

it('no error when primary contact doc is deleted (404)', async () => {
const warnStub = sinon.stub(log, 'warn');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sinon.stub(log, 'warn') mutates the shared log module object.
The repo convention is the stub in beforeEach and afterEach(() => sinon.restore()) at the describe level, which is more defensive. It should not affect if more tests are added in the future.

Example: validate-forms.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @binokaryg, addressed the stub feedback here as we need this fix for the user management app

@freddieptf
freddieptf requested a review from binokaryg August 28, 2026 01:14

@binokaryg binokaryg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing the change request. @freddieptf
Approving

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.

3 participants