Repository navigation
OpenConceptLab/ocl_online#772 | Adding references merges unresolved entries instead of replacing them - #1069
snyaggarwal wants to merge 4 commits into
Conversation
…ntries with the expansion's earlier ones
snyaggarwal
left a comment
There was a problem hiding this comment.
Review: request changes
1. Blocker: the new test fails, and re-adding a reference moves its entry to the end.
- Where:
merge_unresolved_entries(core/collections/models.py, ~L2405) builds[*kept, *found]. A re-evaluated reference's old entry is filtered out ofkeptand comes back at the end throughfound. - Failure:
test_add_references_keeps_earlier_unresolved_entriesaddsone, addstwo, then re-addsone. The result is[two, one], but the test asserts[one, two]. - Why it matters beyond the test: FHIR
$expandraises onunresolved_repo_versions[0]. So re-adding a reference can change which reference$expandnames first, which is the ticket's point. - Fix: replace an evaluated key's entry where it sits, and append only entries that are new.
2. Should-fix: a stale merge base can bring back entries a concurrent delete dropped.
- Where: the merge starts from the in-memory
self.unresolved_repo_versions, loaded when the add starts. - Failure: reference R is deleted while an add runs, and
drop_unresolved_entries_of_deleted_referenceswrites[]. The add then saves R's entry back, because it didn't evaluate R. Health and$expandkeep reporting a reference that no longer exists, until a rebuild. - Fix: re-read the stored list just before merging, and use it as the merge base and as the change baseline. Skip this on the rebuild path, which must still start from
[].
Nits
- Entry keys for
reference.systemandreference.valuesetignorenamespace. This matchesdrop_unresolved_entries_of_deleted_references, and is rare. - The tests cover only
reference.systementries. Value-set, system-version parameter and resource-version entries, and the delete path (add_references(..., attempt_reevaluate=False)), are untested. - The "only what this add found" comment above the save now sits over a merged list. It should say something like "only this field".
Checked, no issue:
- Entry keys and evaluated keys line up for all four entry types.
should_reevaluate=Falsekeeps the system-version and resource-version entries.- The rebuild paths still start from empty, and now save
[]. - The resolve test and the rebuild test would fail before the change and pass after it.
…nd merge into the stored row
|
Fixed in 396ba8e:
|
snyaggarwal
left a comment
There was a problem hiding this comment.
Review round 2 (Expansion Health epic, reviewed with #1070–#1073): approve with nits
The fixes from round 1 hold, at 2bba48c:
- Order:
merge_unresolved_entriesreplaces an evaluated key's entries where they were and appends only new keys, so FHIR$expand'sunresolved_repo_versions[0]stays put when a reference is re-added. - Stale base: the merge starts from the stored row, read just before the save. The rebuild path still starts from
[].
Checked, no issue
- The evaluated keys line up with what each entry type writes:
reference.systemis keyed by (url, version);- a value set by its URL;
- a resource version by the expression, and only when re-evaluating, which is the only time one is written;
system-versionis one key, added only when it's re-evaluated.
- A reference that computes against a
system-versionentry writes noreference.systementry, but its key is still evaluated. So its old entry drops, which is right. - On an auto-generated expansion, a non-forced add keeps the resource-version and
system-versionentries. - Exclude references go through
get_ref_resultstoo, so their keys count as evaluated. - No logical overlap with #1073, which only touches
unresolved_reasonin the not-re-evaluating branch.
Nits
- Merge conflict with #1073 in
core/collections/tests/tests.py. Both add tests right aftertest_add_references_marks_pinned_reference_no_version_holds(~L4420). It's textual only: keep both blocks. Whichever merges second needs a master merge. - Read-then-write isn't atomic. Two adds that overlap on one expansion can still lose one's entries, since each merges into the row it read. That window is far smaller than before, and adds are mostly serialized by
is_processing. FYI only;select_for_updateon that read would close it if it ever matters. - Still open from round 1, and fine to leave: namespace isn't in the keys, and there are no tests for value-set, resource-version or
system-versionentries.
CI: Pylint passes; Tests is still running.
paynejd
left a comment
There was a problem hiding this comment.
Review lead (Claude, for Jon), round 1
Verdict: CHANGES_REQUESTED (head 2bba48c). One small fix before merge: an add that accepts no references can now change the stored unresolved list without marking health (item 1 below). The rest are nits.
Reviewed against OpenConceptLab/ocl_online#772. All three acceptance criteria are met: an add merges and de-duplicates, an add that resolves an entry drops it, and a full rebuild still starts from empty.
Earlier points
- Re-adding moved an entry to the end (blocker): met.
merge_unresolved_entriesreplaces an evaluated key's entries in place and appends only new keys (models.py ~L2390);test_merge_unresolved_entries_keeps_their_ordercovers it. - Stale in-memory merge base (should-fix): met. The merge starts from the stored list read just before the save, and a rebuild starts from
[];test_add_references_merges_into_the_stored_entries_not_a_stale_copycovers it. - Comment above the save: met.
- Namespace not in the entry keys: accepted, as it matches
drop_unresolved_entries_of_deleted_references. - No tests for value-set, resource-version or
system-versionentries: not met, and fine to leave as a nit. - Read-then-write is not atomic: accepted as FYI.
New
- To fix before merge (small): an add that accepts no references can change the unresolved list without marking health out of date.
Collection.add_referencescallsexpansion.add_references(added_references)even whenadded_referencesis empty (every reference rejected, for example as a duplicate), but marks health onlyif added_references:(models.py ~L309-311).- The add still re-evaluates the
system-versionparameter entries (theshould_reevaluate and system_versionsblock). Before this PR that never cleared anything, because the field was written only when the add found something unresolved. Now the entry drops once the version resolves, and a health summary stored as current keeps counting it until the next change. - Fix, in
Expansion.add_referencesright after the save of a changed list:Expansion.mark_health_not_current([self.id]). It bumps the revision and queues nothing, and a build's closingupdate_healthstill computes afterwards.
- Nit:
SYSTEM_VERSION_UNRESOLVED_TYPErepeatsSYSTEM_VERSION_PARAMETER_TYPEin core/collections/health.py:31. One constant, imported from one place, keeps the two from drifting. - Nit: an earlier entry and a new one for the same lookup can differ only as
version: nullagainstversion: "". The key treats them as one, but the final de-duplication compares the JSON, so both stay. Normalising the version before the JSON identity check would collapse them.
CI: Pylint and Tests pass.
Fixes OpenConceptLab/ocl_online#772.
What changed
Expansion.add_referencesnow merges its unresolved entries into the expansion's existingunresolved_repo_versionsinstead of replacing them:system(with its version), its value sets, its resource version (when re-evaluating), and thesystem-versionparameter entries (when it evaluates those).[]was only set in memory.Why
Before this change, each add overwrote the field with only what that add found. So adding A (X unresolved) and then B (Y unresolved) recorded only [Y]. The serializer, expansion health and FHIR
$expandall read this field.Tests
New tests in
ExpansionTest:Focused pylint on the changed files passes (exit 0). The local Docker stack is down, so the tests haven't run locally. This relies on CI's Tests job.
🤖 Generated with Claude Code