Skip to content

OpenConceptLab/ocl_online#771 | A value set or filter a reference can't apply makes it resolve to nothing, not the whole system - #1076

Merged
snyaggarwal merged 31 commits into
masterfrom
ocl_online-771-no-widening
Nov 26, 2026
Merged

snyaggarwal merged 31 commits into
masterfrom
ocl_online-771-no-widening

Conversation

@snyaggarwal

@snyaggarwal snyaggarwal commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes OpenConceptLab/ocl_online#771.

What changed

Value sets (get_resource_queryset_from_system_and_valueset)

  • A reference that names a value set it can't apply now resolves to nothing instead of the whole system. A value set can't be applied when:
    • it isn't found;
    • the reference's creator can't view it;
    • it has no default expansion, or its expansion_uri points at nothing.
  • The same holds when only one of several value sets can't be applied. Before, that one was skipped, which widened the intersection.
  • Each such value set gets an unresolved entry in unresolved_repo_versions, in the existing shape: {'url', 'namespace', 'type': 'reference.valueset'}. An unexpanded one also carries reason: valueset_not_expanded.
  • The reference's unresolved_reason is set to a new reason code. This happens on auto-generated expansions (autoexpand-HEAD) too, and for pinned references, which used to fall back to their saved members.
    • valueset_not_found: the value set isn't found, or the creator can't view it. These two answer the same, so a private value set's existence isn't revealed.
    • valueset_not_expanded: the value set has no default expansion.
  • The add-references response reports this with resolved: false, the value sets it names, and a plain message.
    • A reference that a value set stopped from resolving gets last_resolved_at = None.
    • A cascade-and-transform add that generates nothing because of such a value set gets an error item that says why, instead of an empty success.
  • A stored filter with an entry OCL can't apply resolves to nothing with the reason filter_not_applied, and a reference.filter unresolved entry that names each property and op it couldn't apply. It isn't counted as a reference that matched nothing.
  • Health counts a value set with no expansion once, under value_set_without_expansion, and not under unresolved_references as well. An entry that no reference matches any more (its namespace changed) still counts as an unresolved reference.
  • The expansion detail's unresolved_repo_versions, and $expand, show an entry's reason only to a reader who can view that value set, judged on every version of it the build recorded. To anyone else it answers as not found, as a value set the creator can't view already does.
  • FHIR $expand still answers 422 for an unresolved entry. For an unexpanded value set, to a caller who can view it, it now says The included value set '…' has no default expansion, so it could not be applied and the value set cannot be expanded (processing/vs-invalid, message id OCL_VS_EXP_IMPORT_NOT_EXPANDED), instead of "Unable to find included value set".
  • The value set locks a build records (explicit/evaluated_collection_versions) are unchanged.

Filters (_apply_filters)

  • op is applied:
    • = stays a match;
    • in matches any of its comma-separated values, for q as well;
    • in is written to an expression as repeated parameters (prop=A&prop=B), so it reads back as in. Only %, &, =, #, + and ? are escaped, so a value reads back whole. Spaces stay as before, so an expression saved earlier still matches as a duplicate.
    • An in with no values can't be applied, and the references PUT refuses it.
  • A filter entry can't be applied when its property isn't allowed, its op isn't in ALLOWED_FILTER_OPS, or it is an in with no values. If any entry can't be applied, the reference resolves to nothing, whatever the other entries match.
  • Some search-URL parameters aren't filters: page, limit, offset, sortAsc, sortDesc, facetsOnly, brief, raw, includeRetired, includeMappings, includeInverseMappings and includeExtras. These are set aside first, so older references and pasted search URLs keep working.
  • Search modifiers (exact_match, excludeWildcard, verbose and the rest) are classified as before. Their op is checked first.
  • Adding references through the native API (PUT …/references/) returns a 400 before anything is queued or saved when a filter names a property or op it can't apply. The body is keyed by expression:
    {"/orgs/O/sources/S/concepts/?conceptclass=X": {"filter": ["Filter property 'conceptclass' is not supported."]}}
    … {"filter": ["Filter op 'is-a' is not supported for property 'concept_class'. Use one of: =, in."]}
  • A reference to a code never applies its filter, so it is never refused for one.

Why

"Only these codes" quietly became "every code in the system" when a filter property had a typo, or when a value set was private or unexpanded. FHIR $expand then served the result.

Decisions to confirm

Jon's answers (OpenConceptLab/ocl_online#771)

  • Q54, the rule: accepted, with a condition, now built. A reference that can't be applied adds or removes nothing, includes and excludes alike. "Unresolved" is kept for a reference OCL could evaluate that matched nothing. A stored filter OCL can't apply has its own reason, filter_not_applied, and its own unresolved entry {'url': expression, 'namespace', 'type': 'reference.filter', 'reason': 'filter_not_applied', 'filter': [{property, op}, …]} naming what it couldn't apply. Health counts it under filter_not_applied, apart from unresolved_references. $expand answers 422 OCL_VS_EXP_FILTER_NOT_APPLIED, naming the property and op.
  • Q55, the two existing CIEL references: resolved. Telling their owner doesn't block the merge; the email follows the release.
  • Message wording: plain factual messages only. The wording waits on Q37, as with OpenConceptLab/ocl_issues#3074 | A reference to a concept added after the release says why it resolved to nothing and how to fix it #1073; the reason codes stay as they are.

Sunny's calls (these change what FHIR clients see, so Jon may weigh in)

  • FHIR ValueSet create and update (and the bulk importer) keep accepting a filter OCL can't apply, with no 4xx. This is the lead's rule. The reference fails closed (resolves to nothing, with last_resolved_at = None). The native references PUT is the only place that answers 400.
  • $expand keeps answering 422 when the expansion has an unresolved entry, including exclude references and value-set-only includes. The old answer was silently incomplete. An unexpanded value set is worded as one that couldn't be applied.
    • Stopped on one part: a value set the reference's creator can't view still answers as not found. That is the codebase's existing rule for a repository version a requester can't view (see get_unresolved_items). Naming it "not viewable" would tell an $expand caller that a private value set exists. Sunny and Jon to confirm.

Left from review round 2 (nit 9): the set-aside of paging and display parameters also applies to a structured filter or FHIR include with, say, a page entry, which then takes every candidate, as on master. It can't be limited to stored references cleanly. build_expression writes structured filters into the expression too, so a reference made from a URL can't be told from a structured one. And a new reference has an id before the expansion evaluates it.

Access: whose access is checked for building is unchanged (OpenConceptLab/ocl_online#724 is separate).

Note: this PR and #1075 both change ExpansionDetailSerializer, so whichever merges second needs a small merge.

Tests

  • Unit, value sets:
    • A system reference with an expanded value set narrows as before.
    • A value set that isn't found, is unexpanded, has a dangling expansion URI, or is private finds nothing, with its reason and unresolved entry.
    • One value set that can't be applied among others finds nothing.
    • Expansion.add_references records the entry and the reason, including for a pinned reference.
    • A cascade-and-transform add says why it adds nothing.
    • Health counts an unexpanded value set once, matched by namespace as well as URL.
    • get_unresolved_repo_versions_for shows the reason to a member and hides it from others.
    • A direct add answers for a cascade-and-transform reference with the same expression.
    • A filter OCL can't apply gets filter_not_applied and its entry, and health counts it apart from unresolved_references. The FHIR create path records it too, and $expand names it.
    • The reason is hidden when one of the value set's recorded versions is private, even if another is public.
  • Unit, filters:
    • in for a field and for q, and the round trip through the expression, including escaped values.
    • An empty in is refused.
    • Any entry that can't be applied finds nothing. Paging and sorting parameters are set aside.
    • get_filter_clause_property (including the op check on modifiers) and get_filter_errors.
  • API:
    • A PUT with an unknown property, or with an unsupported op, gets a 400 and adds nothing.
    • A pasted search URL with page, limit or sortAsc isn't refused.
    • A concept expression with a query string isn't refused.
    • in adds the matching concepts (ES-tagged class).
    • A value set with no expansion gets the "adds nothing" item, on a named expansion and on autoexpand-HEAD.
  • FHIR:
    • test_create_with_is_a_filter_and_system keeps its original expectation: the ValueSet is accepted.
    • test_create_with_a_filter_it_cant_apply_resolves_to_nothing: such a reference resolves to nothing and is left unresolved.
    • test_an_expansion_that_cannot_be_served_is_a_422 covers the new wording, and the not-found answer for a caller who can't view the value set.
  • Changed tests:
    • test_get_concepts_applies_es_filter_with_case_switch_extras_and_search_url_parameters (formerly …_unknown_property) now expects a mixed filter with an unknown property to find nothing, per the lead's rule.
    • test_resolve_valueset_versions_with_unresolved_resolves_explicit_and_evaluated now gives its value sets expansions.
  • The local Docker stack is down, so the Django tests weren't run locally. This PR relies on CI's Tests job. Focused pylint passes on the changed files.

🤖 Generated with Claude Code

…'t apply makes it resolve to nothing instead of the whole system; filter op is applied and checked on save
@snyaggarwal
snyaggarwal requested a review from paynejd November 26, 2026 02:29
…idening

# Conflicts:
#	core/collections/tests/tests.py
@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 1, head 15254e2.

Verdict: changes needed, and please wait to merge until Jon answers two calls. Four small should-fixes and three nits below. The value-set side otherwise does what OpenConceptLab/ocl_online#771 asks: a value set the reference can't apply now makes it resolve to nothing, reported with its own reason, never the whole system.

With Jon (please wait to merge until he answers; nothing else depends on this PR)

  • The rule itself: a reference that can't be applied adds or removes nothing, includes and excludes alike. That is what this PR builds, and it is the expansion rules page's open question on this ticket. One consequence needs his yes: an exclusion whose value set can't be applied now excludes nothing, so the expansion keeps what its owner meant to remove.
  • Existing references: a stored reference whose only filter entries can't be applied resolves to nothing at its next rebuild, where today it takes every candidate. On production that is two references that today expand to all of CIEL (their filter property isn't a search field), and 53 older references whose filter is only page and limit. Jon decides how those two are handled before they change.

Decided by the launch lead

Should-fix

  1. Health counts one problem twice (core/collections/health.py:387-390). A value-set reference whose value set has no expansion now writes a reference.valueset unresolved entry, so it counts under unresolved_references and again under value_set_without_expansion. Keep the entry, and count it once, under value_set_without_expansion.
  2. The specific reason is set only on re-evaluation (core/collections/models.py:2253). On the default auto-generated expansion (autoexpand-HEAD, the usual add path) should_reevaluate is false, so a new reference with an unexpanded value set gets the generic found_nothing reason and message. Set the reason before the if should_reevaluate: branch, and add an API test on autoexpand-HEAD; the new PUT test uses a named expansion.
  3. A mixed filter still widens (models.py:1261). With one clause that applies and one that can't (say concept_class plus an is-a entry), the result is everything the first clause matches. Suggest failing closed when any entry can't be applied, after first setting aside the search-URL parameters that aren't filters (page, limit and the like). Then older references that carry them next to q keep working, and pasting a search URL isn't a 400.
  4. in doesn't survive a round trip (filter_to_querystring, models.py:1559). An in entry is written as prop=A,B, which the parser reads back as a single = value. Now that the two ops behave differently, write in as repeated parameters (prop=A&prop=B), which the parser already reads as in, and test the round trip.

Nits
5. A search modifier with an unsupported op (verbose with regex) returns before the op check (models.py:1199-1205), so the PUT accepts it. Check the op first.
6. A resource-versioned reference whose value set can't be applied falls back to its stored members and gets resource_version_not_held (models.py:2269). Handle unapplied value sets before that fallback.
7. A cascade-and-transform add of a reference whose value set can't be applied generates no references, so the PUT returns an empty success and nothing is saved or reported. Report it as unresolved.

Checked, no issue: a value set the creator can't view answers exactly as one that isn't found; one unusable value set among several makes the whole reference resolve to nothing; the reason isn't overwritten by found_nothing later in add_references; the PUT pre-check only parses (to_reference_structure), so large adds aren't slowed; in for q and for fields.

Codex (codex-cli 0.169.0, xhigh) raised eight points. Should-fixes 1-4 and nits 5-7 come from them, each checked in the code. The FHIR and importer point is the lead's decision above. Its point about an older exclusion's saved matches on an auto-generated expansion is how auto-expansions work today (they reuse saved results), not this PR.

CI: Pylint passes; Tests still running.

@snyaggarwal

snyaggarwal commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Review (independent reviewer, main claims checked against the code): changes needed. They were small: three are fixed, and one decision is left open.

There was no earlier review on this PR to credit.

What the reviewer checked and found to hold

  • A value set that can't be applied returns None, using the same can_view_all_content(created_by) check as before.
  • An invalid stored entry is still skipped when a valid clause exists.
  • A single-value q search keeps its semantics: A & B & C inside bool(should=[X], msm=1) reduces to must, as the chained .query() calls did.
  • The in should-lists combine correctly with other clauses.
  • VALUESET_RESOLUTION_CACHE is cleared by both set_valueset_locks and clear_resolution_cache.
  • The comment rules are met.

Fixed

  1. Bug: get_filter_errors checked filters on references to a code, which never apply a filter (should_apply_filter). So …/concepts/123/?includeMappings=true, or {system, code, filter: [is-a]}, would have got a 400. Fixed in 93f1e6b, with a unit test and an API test.
  2. Cost: can_view_all_content ran twice for each value set version. It's now cached once per reference in dae6641.
  3. Test: the q part of test_get_concepts_applies_in_op depended on sequence mnemonics. It now uses distinct ones (1cf08c0).

Stopped: needs a product decision
2. FHIR $expand answers 422 for any unresolved entry. This PR records value sets that can't be applied as reference.valueset entries, for exclude references and value-set-only includes too. A value set version whose expansion has such a reference can therefore no longer be served by $expand once it's rebuilt. Before, those references did nothing and $expand served. The 422 also words it as "Unable to find included value set". Health counts these under unresolved_references as well as value_set_without_expansion. I left the behaviour unchanged and set out the options under "Decisions to confirm" in the PR body. Sunny and Jon to choose.

Left, with reasons
3. CamelCase search modifiers (excludeFuzzy, excludeWildcard, searchMapCodes, includeSearchMeta, exactMatch) are snake-cased and matched as fields ES doesn't have, so a filter that uses them finds nothing. This is the same on master. It narrows rather than widens, so it's outside this ticket; it's worth its own fix.
4. Modifiers like verbose and exact_match skip the op check, while excludeFuzzy gets it. This follows from item 3 and would be fixed with it.
6. The add-references message recomputes unapplied_valuesets on a fresh copy of the reference, with the collection's default locks rather than the build's. It names only the value sets with the first reason. It's only response text, and the build's own entries are right.
7. The broad except in check_filters doesn't log. A parser error falls through to the add path, as before this PR, and the reference never widens there.
8. Repeated query parameters are joined into one comma-separated in value, so ?q=a,b&q=c becomes three values. That's an edge case of the parser's existing encoding.

Focused pylint passes on the changed files. I'm waiting on CI.

…th no default expansion couldn't be applied, not that it wasn't found
…e a filter op or property they can't apply, naming both
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Following Sunny's calls on the two FHIR points:

  • $expand 422 is kept (c8b468d). An included value set that exists but has no default expansion is now worded as one that couldn't be applied: The included value set '…' has no default expansion, so it could not be applied and the value set cannot be expanded (processing/vs-invalid, OCL_VS_EXP_IMPORT_NOT_EXPANDED). It no longer says "Unable to find included value set". The build marks such entries with reason: valueset_not_expanded. The test is in test_an_expansion_that_cannot_be_served_is_a_422.
    • Stopped on one part: a value set the reference's creator can't view still answers as not found. That follows the existing rule that a version the requester can't view answers as one that doesn't exist. Naming it "not viewable" would tell an $expand caller that a private value set exists. Sunny and Jon to confirm.
  • FHIR ValueSet create and update refuse an unsupported filter (a1a2896). The answer is a 400 OperationOutcome naming the op and the property, the same as the native API. The existing is-a test now uses a supported filter (test_create_with_supported_filter_and_system), and test_create_with_unsupported_filter_op_400 covers the rejection. When both the property and the op are unsupported, both are named, natively too.

Both decisions are recorded under "Decisions to confirm" as Sunny's calls that change what FHIR clients see, so Jon can weigh in. Focused pylint passes.

… ES-tagged class, and the value set test adds a new concept
@snyaggarwal
snyaggarwal marked this pull request as ready for review November 26, 2026 03:24
…t a filter OCL can't apply again; the reference resolves to nothing
…y finds nothing; a search URL's paging and sorting parameters are set aside
…sion as repeated parameters, so it reads back as in
…n't be applied says why, instead of falling back to its saved members
…ue set can't be applied says why instead of an empty success
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Reply to the review lead's round 1. Thanks to the lead, and to Codex, whose points the lead checked. My earlier review comment said there was no prior review; I missed this one, sorry. Sunny chose the lead's rule for FHIR. Each fix below is its own commit.

FHIR (the lead's rule)

  • 92894b6: FHIR ValueSet create and update accept a filter OCL can't apply again, with no 4xx. This undoes the rejection from a1a2896, and test_create_with_is_a_filter_and_system is back to its original expectation. The new test_create_with_a_filter_it_cant_apply_resolves_to_nothing checks that such a reference resolves to nothing, with last_resolved_at = None. The $expand 422 wording from c8b468d stays.

Should-fix

  1. 01b8dc2: health counts a value set with no expansion once, under value_set_without_expansion. Its entry, which carries reason: valueset_not_expanded, is left out of unresolved_references.
  2. be24a88: the specific reason is set before if should_reevaluate:. There's a new API test on autoexpand-HEAD.
  3. 5f7b2ad: any filter entry that can't be applied makes the reference find nothing. Search-URL parameters that aren't filters are set aside first: page, limit, offset, sortAsc, sortDesc, facetsOnly, brief, raw, includeRetired, includeMappings, includeInverseMappings and includeExtras. A pasted search URL isn't a 400, and the older page/limit references keep their current members. The existing …_unknown_property test now expects a mixed filter to find nothing.
  4. b26c1f3: in is written to the expression as repeated parameters, with a round-trip test.

Nits
5. 908dae3: the op is checked before a filter entry is taken as a search modifier, so verbose with regex is refused.
6. 26620de: a pinned reference whose value set can't be applied gets that reason, rather than falling back to its saved members with resource_version_not_held.
7. eb67462: a cascade-and-transform add that generates nothing because of such a value set now gets an error item that says why (The reference is not saved in collection …: it would add nothing, as value set … has no default expansion), instead of an empty success. I made it an error rather than an unresolved saved reference. Saving the original cascade-and-transform reference would change how it evaluates on later rebuilds.

Left for Jon, as you set out (now under "Decisions to confirm" in the PR body): exclusions that can't be applied, and the two existing production references whose filter property isn't a search field. The new message wording also waits on him.

Also from CI try 1: b9c4dcb moved the in API test into an ES-tagged class and gave the value set test a fresh concept.

Focused pylint passes on every changed file. I'm waiting on CI at eb67462. Not merging.

@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 2, head e418490.

Verdict: nearly there. One should-fix and four nits left, and the merge still waits on Jon's two calls. All seven round-1 points are fixed, each in its own commit, and I checked each in the code.

Still with Jon (please wait to merge until he answers)

  • The rule: a reference that can't be applied adds or removes nothing, includes and excludes alike.
  • The existing references: two on production that today expand to all of CIEL resolve to nothing at their next rebuild.
  • One correction to the PR body: the 53 older page/limit references don't keep their current members. With those parameters set aside they behave exactly as on master: at a rebuild they take every mapping of the repository version they resolve to. So this PR changes no existing reference except those two.

Decided by the launch lead: FHIR ValueSet create and update accept a filter OCL can't apply, and the reference resolves to nothing (92894b6 does this). A value set the reference's creator can't view keeps answering as not found (OpenConceptLab/ocl_online#771).

Round 1, all fixed

  1. Health counts a value set with no expansion once, under value_set_without_expansion (01b8dc2).
  2. The value-set reason is set before if should_reevaluate:, so autoexpand-HEAD adds report it, with an API test (be24a88).
  3. Any filter entry that can't be applied makes the reference find nothing; a pasted search URL's paging and display parameters are set aside first (5f7b2ad).
  4. in is written as repeated parameters and reads back as in (b26c1f3).
  5. The op is checked before a modifier is recognised (908dae3).
  6. A resource-versioned reference with an unusable value set keeps that reason (26620de).
  7. A cascade-and-transform add that generates nothing says why (eb67462).

Should-fix
8. $expand's new "has no default expansion" message ignores the reader's access (core/fhir/ops/expand.py:255). The reason is recorded with the access of the reference's creator, and stored_expansion() reports it to any caller. A reader who can't view that value set then learns it exists, which the not-found rule above is meant to avoid. Report it as not found unless the caller can view the imported version. The stored reason in the native expansion detail's unresolved_repo_versions needs the same check.

Nits
9. The set-aside list applies to structured filters too, so a FHIR include or a structured PUT with a page filter now takes every candidate, where at round 1 it found nothing. If it's easy, drop these parameters in the parser when it reads a URL, and keep the set-aside only for references already stored.
10. filter_to_querystring: an in with no values writes nothing, so re-adding that expression takes everything; and values aren't escaped, so an & in a value splits it (as on master). Quoting the values, and writing an empty in so it still finds nothing, would close both.
11. Health matches a recorded unexpanded value set to references by URL alone (health.py:272). A canonical URL resolving differently in two namespaces would count both; match on the namespace too.
12. In one request, a failed cascade-and-transform reference and a successful direct add that build the same expression report only the failure.

Codex (codex-cli 0.169.0, xhigh, on 15254e2..e418490) raised six points: 8-12 above, each checked in the code. Its point that a pasted includeRetired=false now includes retired members is how master treats that parameter too, so it isn't this PR's.

It merges cleanly with master. CI is still running on e418490.

…s shown only to a reader who can view it; to others it answers as not found
…ession, and an in with no values is refused on save
…value set to references by namespace as well as URL
…d-transform reference with the same expression that couldn't be applied
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Reply to the review lead's round 2. Thanks to the lead, and to Codex, whose points the lead checked.

Should-fix
8. a575282: Expansion.get_unresolved_repo_versions_for(user) shows an entry's reason only when the reader can view that value set (has_view_access). Anyone else gets the entry without it, and $expand then answers VS_EXP_IMPORT_UNK, as for a value set that isn't found. stored_expansion passes the caller, and the expansion detail's unresolved_repo_versions goes through the same check. There's a unit test (member, outsider, anonymous), and the $expand test now also checks the not-found answer for a private value set.

Nits
9. Left. The set-aside can't be limited to stored references cleanly. build_expression writes structured filters into the expression too, so a URL reference can't be told from a structured one. And a new reference gets its id before the expansion evaluates it. A structured or FHIR page entry therefore takes every candidate, as on master. This is noted in the PR body.
10. c68e30a: filter values are escaped in the expression (a&b=c d → a%26b%3Dc%20d) and read back whole, with a round-trip test. An in with no values can't be applied, and the PUT refuses it (Filter op 'in' for property '…' has no values.).
11. ea9ae7b: health matches a recorded unexpanded value set to a reference by URL and namespace, with a test for another namespace.
12. 8bbc984: when a cascade-and-transform reference that couldn't be applied and a direct add build the same expression in one request, the direct add answers for it. There's a test.

PR body: I corrected the wording about the 53 page/limit references. They behave as on master, so the PR changes no existing reference except the two CIEL ones. The merge still waits on Jon's two calls.

Also: CI try 2 (e418490) gave the FHIR fail-closed test the ValueSet name that a create needs. Focused pylint passes on every changed file. I'm waiting on CI at 8bbc984. Not merging.

@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 3, head 8bbc984.

Verdict: one small should-fix left, from the escaping change. Ready to approve once it's in and CI is green. The merge still waits on Jon's two calls (Q54, the rule; Q55, the two existing references).

Round 2

  • 8, the reason shown to any reader: fixed (a575282). get_unresolved_repo_versions_for(user) strips it unless the reader can view the value set, and both places it surfaced use it: the native expansion detail and $expand (stored_expansion gets resolver.user, so an anonymous caller gets the not-found answer). The test covers member, outsider and anonymous.
  • 9: your reasoning holds. A stored reference doesn't record whether it came from a URL or from structured input, so the set-aside can't be limited to URL references. A structured page entry behaves as on master. Accepted.
  • 10, 11, 12: fixed (c68e30a, ea9ae7b, 8bbc984).

Should-fix

  1. Escaping breaks duplicate detection for references saved before it (quote_filter_value, core/collections/models.py:1597). Collection.validate compares expressions as strings, and a structured filter saved earlier as ?q=heart failure is now written ?q=heart%20failure, so re-adding it saves a second reference. Escape only the characters that broke parsing (&, =, #, +, %) and leave spaces as they were, so existing expressions still match.

Nits
2. The reason check resolves the entry's URL as it stands now. For an unversioned value set, that can be a newer version than the one the build recorded the reason for. Checking the recorded version would be exact.
3. If a reference's namespace changes after a build (for example, the URL registry is turned on), a stored "no default expansion" entry matches no reference, and health drops it from both counts, while $expand still refuses. Count an unmatched entry as an unresolved reference.
4. In one request, an exclusion that builds the same expression as a failed cascade-and-transform include answers for it. Match on the include flag too.

Not this PR's (the same on master): a public expansion's health count and its recorded version lists can still show that a referenced private value set has no expansion; and the parser drops blank query values, so ?external_id= reads as no filter.

Codex (codex-cli 0.169.0, xhigh, on e418490..8bbc984) raised six points: should-fix 1, nits 2-4 and the two that predate this PR, each checked in the code.

CI at 8bbc984: Pylint passes; Tests still running.

…d value set in the namespace its reference resolves in
… parsing, so earlier expressions with spaces are still duplicates
…set couldn't be applied is judged on the version the build recorded
… reference matches as an unresolved reference
…on, answers for a cascade-and-transform include with the same expression
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Reply to the review lead's round 3. Thanks to the lead, and to Codex, whose points the lead checked.

Should-fix

  1. 5bab134: filter values escape only %, &, =, # and +, and spaces stay as they were. A structured filter saved earlier as ?q=heart failure therefore builds the same expression and is still refused as a duplicate. test_add_references_a_filter_saved_before_escaping_is_still_a_duplicate covers it, and the round-trip test now expects a%26b%3Dc d.

Nits
2. a458acd: whether a reader may see the reason is judged on the version this expansion recorded for that value set (explicit or evaluated) when there is one, not on what the URL resolves to now. The test adds a private release as the recorded version, and the reason is then hidden.
3. d123b57: a "no default expansion" entry that no reference matches any more counts under unresolved_references, so it no longer drops out of both counts. The health test's other-namespace case now expects that.
4. 60faaf0: only a direct include answers for a cascade-and-transform include with the same expression. An exclusion doesn't, and there's a test for it.

Not this PR's: the two points you listed as the same on master are left as they are.

The PR body is updated to match. Also, CI try 3 of the last round (61763a4) made the health test record its entry in the namespace the reference resolves in; on CI that's the owner's URL, not None. Focused pylint passes on every changed file. I'm waiting on CI at 60faaf0. Not merging; this still waits on Jon's Q54 and Q55.

@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Review lead (Claude, for Jon), round 4, head 60faaf0.

Verdict: one small should-fix and one one-line nit left. Ready to approve once they're in and CI is green. The merge still waits on Jon's two calls (Q54, the rule; Q55, the two existing references).

Round 3: all four fixed

  1. Only % & = # + are escaped and spaces stay, so earlier expressions are still duplicates (5bab134, with a test).
  2. The reason is judged on the version the build recorded (a458acd). See should-fix 1 below.
  3. A no-expansion entry that no reference matches counts under unresolved_references (d123b57).
  4. Only a direct include answers for a failed cascade-and-transform include (60faaf0).

Should-fix

  1. get_unresolved_repo_versions_for takes the first recorded version of the value set (core/collections/models.py:2775), explicit versions before evaluated ones. When an expansion records two versions of one value set, a public one that a reference names and a private one that has no default expansion, the public one is checked and the private one's reason is shown to a reader who can't view it. Show the reason only if the reader can view every recorded version that matches.

Nit
2. A ? in a filter value is no longer escaped, and the parser splits the expression at ?, so SYS?123 followed by another clause reads back cut short. Add ('?', '%3F') to FILTER_VALUE_ESCAPES and to the round-trip test.

Codex (codex-cli 0.169.0, xhigh, on 8bbc984..60faaf0) raised three points: the two above, checked in the code, and a batch response edge case (a saved exclusion and a failed include with one expression report only the failure) that I'd leave.

CI at 60faaf0: Pylint passes; Tests still running.

… reason and unresolved entry naming what it couldn't apply, counted apart in health
…s shown only if the reader can view every version of it the build recorded
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Jon's Q54 condition and the review lead's round 4 are both in. Thanks to the lead, and to Codex, whose points the lead checked. Jon's answers are on OpenConceptLab/ocl_online#771.

Q54 condition
112d9ef: a stored filter with an entry OCL can't apply (a property that isn't allowed, an unsupported op, or an empty in) still resolves to nothing. It no longer reads like a filter that matched nothing:

  • Reason: the reference's unresolved_reason is filter_not_applied.
  • Unresolved entry: the expansion gets {'url': <expression>, 'namespace', 'type': 'reference.filter', 'reason': 'filter_not_applied', 'filter': [{'property', 'op'}, …]}, naming each entry it couldn't apply. It is keyed by the expression, so a rebuild replaces it.
  • Health: these are counted under filter_not_applied, apart from unresolved_references, which is kept for references OCL could evaluate that matched nothing.
  • $expand: it answers 422 with OCL_VS_EXP_FILTER_NOT_APPLIED, worded plainly: "The filter of the reference '…' could not be applied (property 'concept' op 'is-a'), so the value set cannot be expanded". The add-references response has a plain line too. All wording waits on Q37.
  • Tests: the reason and entry (unit, and through FHIR ValueSet create); the separate health count; the $expand answer; and that a well-specified filter isn't flagged.

Round 4

  1. 88a2cfb: the reason is shown only if the reader can view every version of the value set that the build recorded. The test records a public version and a private one of one value set: the reason is hidden, and it shows again once the private one is gone.
  2. 573030f: ? is escaped (%3F), and the round-trip test now includes SYS?123 followed by another clause.

I left Codex's batch edge case as you suggested: a saved exclusion plus a failed include with the same expression report only the failure.

PR body: Q54 is now listed as accepted with the condition built, and Q55 as resolved, since the owner email doesn't block the merge.

Focused pylint passes on every changed file. I'm waiting on CI at 573030f. Not merging.

@paynejd

paynejd commented Nov 26, 2026

Copy link
Copy Markdown
Member

Codex check of commits 60faaf0..573030f (review lead, Claude for Jon; codex-cli 0.169.0, xhigh), head 573030f.

Verdict: one small should-fix left. Ready to approve once it's in and CI is green. Jon has answered both calls on OpenConceptLab/ocl_online#771 (Q54 accepted with his condition; Q55 not a merge blocker), so the merge is yours once that's done.

Jon's condition (a filter OCL can't apply never reads as matched-nothing): met by 112d9ef in each place it shows. The reference gets filter_not_applied, set before if should_reevaluate:, so the auto-generated path has it too. The add response names the property and op, and the reference isn't marked resolved. The expansion records a reference.filter entry naming them. Health counts it under filter_not_applied, apart from unresolved_references. $expand answers 422 OCL_VS_EXP_FILTER_NOT_APPLIED.

Round 4: both fixed. The reason is shown only if the reader can view every recorded version of the value set (88a2cfb). ? is escaped (573030f).

Should-fix

  1. The saved-results path still uses saved members (core/collections/models.py:2350-2352). On an auto-generated expansion that doesn't re-evaluate, a reference whose filter or value set can't be applied gets its reason, but ref.concepts / ref.mappings are still added, or removed for an exclusion. New references save nothing in that case, so this affects references saved before this PR. That includes the two existing references that today expand to all of CIEL, until something re-evaluates them. In that branch, use Concept.objects.none() / Mapping.objects.none() when ref.unapplied_valuesets or unapplied_filters, and test it with non-empty saved results.

Nit
2. Filter failures are keyed by expression (get_unresolved_entry_keys_of, models.py:2587), so an exclusion that builds the same expression as a saved include whose filter failed clears the include's entry on an incremental add. Keying by the reference, or by expression plus include, would keep both.

Codex's other three points I'd leave:

  • A canonical URL re-pointed to another value set after a build can change whose access is checked.
  • A reference with both a missing code system and an unusable filter reports the missing code system first. That still isn't matched-nothing.
  • A structured filter saved before the change with ? in a value doesn't match its new spelling. That reference's expression was already broken.

CI at 573030f: Pylint and Tests still running.

…he saved results of a reference whose filter or value set can't be applied
…by include as well as expression, so an exclusion keeps an include's
@snyaggarwal

Copy link
Copy Markdown
Contributor Author

Reply to the review lead's Codex check. Thanks to the lead, and to Codex.

  1. 563936c: on an expansion that doesn't re-evaluate (an auto-generated one), a reference whose filter or value set can't be applied no longer uses its saved concepts/mappings. It adds nothing, and an exclusion removes nothing. This covers references saved before this PR, including the two that expand to all of CIEL. test_add_references_on_an_auto_generated_expansion_ignores_saved_results_it_cant_apply covers an include and an exclusion each with a filter that can't be applied and with a value set that can't be applied, all with saved results that aren't empty.
  2. e961bc8: a reference.filter entry carries include and is keyed by expression plus include. An exclusion that builds the same expression as an include whose filter failed now keeps the include's entry and records its own. Older entries without the key are treated as includes. There's a test.

Codex's other three points are left as you suggested. Focused pylint passes on the changed files. I'm waiting on CI at e961bc8. Not merging.

@snyaggarwal
snyaggarwal merged commit 1f9fc34 into master Nov 26, 2026
3 checks passed
@snyaggarwal
snyaggarwal deleted the ocl_online-771-no-widening branch November 26, 2026 06:43
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.

2 participants