Skip to content

Fix orphan code toggling behaviour - #3231

Merged
Jongmassey merged 4 commits into
mainfrom
Jongmassey/fix-orphan-behaviour
Sep 14, 2026
Merged

Jongmassey merged 4 commits into
mainfrom
Jongmassey/fix-orphan-behaviour

Conversation

@Jongmassey

@Jongmassey Jongmassey commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #3232 and thereby ensures that if a parent code unrelated to a search is "toggled on and off" (i.e. set to unresolved then included) its children are correctly included.

Along the way we discovered some unexpected behaviour re: explicitly excluded codes - in the scenario described above any explicitly excluded child codes would transition to included in the backend but no the frontend. This PR contains a commit to ensure that their excluded state is preserved.

@rw251
rw251 force-pushed the Jongmassey/fix-orphan-behaviour branch from 7bb837b to 542e40f Compare September 11, 2026 08:18
@rw251
rw251 force-pushed the Jongmassey/fix-orphan-behaviour branch from 542e40f to 7e18385 Compare September 11, 2026 09:41
@rw251
rw251 marked this pull request as ready for review September 11, 2026 09:43
Jongmassey and others added 4 commits September 14, 2026 08:14
Refactor previous multiple orphan deletion tests into single test
as one subsumed the other.

Expect explicitly excluded orphan codes to not be deleted.
If they are not kept, then if a user (accidentally) un-resolves their
parent then they will silently disappear from the backend state.
If the parent code is then re-included (as might be expected in the case
of an accidental click), they would be re-added as included not excluded

Add orphan deletion/re-inclusion test for an uploaded codelist,
i.e. one with no searches from the outset, to replicate a
uploaded-codelist specific bug encountered in production.
Users may accidentally and temporarily un-resolve a code which has
explicitly excluded descendants.
This commit ensures that these explicitly excluded codes (and their
descendants) remain, and are no silently removed or
silently re-added as with their state flipped to included
if the parent is re-included.
In a codelist without searches, deselecting a root code causes the hierarchy to be destroyed server side, but not client side. This is arguably desired behaviour as it allows the user to quickly add missing codes from a large hierarchy by toggling the root code on and off. However there is a bug which means that reselecting the root code causes the UI to display (correctly) that all children are implicitly included, but the back end only retains the root code. Saving the codelist reveals this and all children are excluded. This is a failing test for that scenario.
After orphan code(s) are deleted from a codelist, this may cause the
parts of the hierarchy they exist in to be deleted.
That meant that when it came time to re-include these codes,
we weren't able to ascertain their descendants for inclusion.

This commit creates a fresh hierarchy for the purposes of re-inclusion.

It also refactors the bulk codeobj insertion used by the re-inclusion
process as to avoid the possibility of unique constraint violations.
@Jongmassey
Jongmassey force-pushed the Jongmassey/fix-orphan-behaviour branch from 7e18385 to ac2d849 Compare September 14, 2026 07:29
@Jongmassey Jongmassey changed the title Fix orphan behaviour Fix orphan code toggling behaviour Sep 14, 2026
@Jongmassey
Jongmassey merged commit 77fac05 into main Sep 14, 2026
9 checks passed
@Jongmassey
Jongmassey deleted the Jongmassey/fix-orphan-behaviour branch September 14, 2026 07:34
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.

Toggling a root code in a search-less codelist causes inconsistency

2 participants