Repository navigation
OpenConceptLab/ocl_issues#3065 | repair_reference_systems fills in system on legacy concept and mapping version references - #1043
Conversation
…stem on legacy concept and mapping version references, dry run by default
snyaggarwal
left a comment
There was a problem hiding this comment.
Round 1 verdict: ready to merge once CI passes. Four optional nits on 25af836. Fixes follow in this PR.
What checks out:
- The candidates: references with no
systemand no value set, in every collection version. - The parsing: it uses the same parser that adding references uses.
- What's saved:
system, pluscode,resource_versionandreference_typeonly where they're missing or wrong. - The update: it's guarded on
systemstill being empty, so a reference changed meanwhile is left as it is. - What doesn't change: there's no re-evaluation, no expansion is rebuilt, and no member is touched. References aren't in the search index, so
update()leaves nothing stale there. - What's left alone: source-version expressions and disagreeing fields are listed with their reasons.
| return None, 'its expression names a source version too' | ||
| for field in ('code', 'resource_version'): | ||
| if getattr(reference, field) and getattr(reference, field) != getattr(parser, field): | ||
| return None, f'its {field} disagrees with its expression' |
There was a problem hiding this comment.
Nit (optional): the code check can mistake encoding for disagreement. The parser reads code from the URL as written, percent-encoded, while an older save may hold the decoded form, so A%2FB and A/B look different. Comparing decode_string of both sides would keep a valid reference from being left as 'its code disagrees with its expression'.
| if not saved: | ||
| self.totals['left: changed since it was read'] += 1 | ||
| return {**report, 'left': 'changed since it was read'} | ||
| self.totals['repaired' if self.options['apply'] else 'would repair'] += 1 |
There was a problem hiding this comment.
Nit (optional): LEFT lines for non-version references will dominate a production dry run. Most candidates are probably references whose expression doesn't name a version at all. Counting those, and keeping them in --output, while printing a line only for changes and the other reasons, would keep the 1,743 repairs readable.
| reference.refresh_from_db() | ||
| return reference.system, reference.code, reference.resource_version, reference.reference_type | ||
|
|
||
| def test_a_concept_version_reference_gets_its_system(self): |
There was a problem hiding this comment.
Nit (optional): no test that a second run changes nothing. The production run relies on being safe to stop and start again. A test that a second --apply repairs nothing would pin that.
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = ('Fills in system on legacy references that have none and no value set, whose expression names a concept ' |
There was a problem hiding this comment.
Nit (optional): the help text doesn't say how this fits with the health backfill. The repair changes reference fields that health reads. Saying to run it before backfill_expansion_health (#1031) avoids stored health that doesn't count the repaired references.
…ists only references worth reading, says to run before the health backfill, and is tested for reruns
|
Round 1's four nits are fixed in 8eb8001.
Local Elasticsearch is down, so CI is the first run of the tests; pylint is clean. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Round 2 verdict: ready to merge once CI passes. No findings on 8eb8001.
Round 1's four fixes check out:
- Codes: they're compared decoded, so the URL's form and an older save's agree, and a test covers
A%2FBagainstA/B. - Output: references that name no version are counted and kept in
--output, but don't get a line each. - Reruns: a second
--applyrepairs and lists nothing. - Help text: it says to run before
backfill_expansion_health.
Nothing else turned up on a second read of the whole PR. A benchmark on local data is running separately, and its numbers will be added here. CI is the first run of the tests, because local Elasticsearch is down.
…nly the fields it uses, not every collection column
|
Benchmark on a local database (2.22M references, 518 MB), run at 25af836, then again with 04cc86e's narrower query. Local data: 1,485 references have no
|
For OpenConceptLab/ocl_issues#3065 (epic OpenConceptLab/ocl_issues#2942), as Jon decided on Nov 23. Some legacy references, created Oct 2023 to May 2024, have an expression that names a concept or mapping version (
/orgs/<org>/sources/<source>/concepts/<code>/<version>/) but nosystem. OCL can't resolve them, so they bring in nothing.What it does
systemand no value set whose expression contains/concepts/or/mappings/, in every collection version. It parses each expression with the current parser (CollectionReferenceExpressionStringParser), then saves:system;codeandresource_version, where they're missing. Most on collection HEADs already have them, and some in older collection versions have neither;reference_type, when its default (concepts) disagrees with a mapping expression.codeorresource_versiondisagrees with its expression.update(), so nothing is re-evaluated, no expansion is rebuilt, and no member is added or removed. The update applies only while the reference still has nosystem, so one changed meanwhile is left as it is.--outputwrites the same as JSON lines, as the before-and-after record. Totals come at the end.Afterwards
resource_versioned_references, and the convert dialog (OpenConceptLab/ocl_issues#3008 | preview and convert resource-versioned references (API) #1033, OpenConceptLab/ocl_issues#3008 | Convert resource-versioned references, showing what each conversion keeps oclweb3#111) offers them; until now, OpenConceptLab/ocl_issues#3008 | preview and convert resource-versioned references (API) #1033 skips them as "it has no system".Tests
core/collections/tests/tests_repair_reference_systems.pyhas 8 tests:system;codeandresource_versionare filled in where missing;systemor a value set aren't touched;The local Elasticsearch container is down, so CI is the first run of these tests; pylint is clean on the new files.
🤖 Generated with Claude Code