Skip to content

OpenConceptLab/ocl_online#737 | Invalid reference IDs answer 404, fuzzy search answers on mapping and collection lists, HEAD answers as GET on details, default expansions stay - #1047

Open
paynejd wants to merge 4 commits into
masterfrom
fix/737-500s
Open

paynejd wants to merge 4 commits into
masterfrom
fix/737-500s

Conversation

@paynejd

@paynejd paynejd commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Part of OpenConceptLab/ocl_online#737. That ticket keeps its other items, so this PR doesn't close it.

What changes

  • Reference detail, invalid ID → 404. CollectionReferenceView passed the URL's reference ID straight to filter(id=…), so a GET, HEAD or DELETE with a non-numeric ID (versioned route), or one too long for an integer, answered 500. It now parses the ID as the reference's concept and mapping lists already do (ASCII digits only, else 404), through one helper both views share.

  • Fuzzy search on mapping lists and a collection's concept list → 200. BaseAPIView reads _source_versions and _extra_filters for a fuzzy search and for search stats, but only the source concept list sets them, so ?fuzzy=true on /mappings/, a source's mappings or a collection's concepts or mappings answered 500. Both now default to None, so those searches keep to the URL's repository through __apply_scope_filters, as plain search does.

  • HEAD on a detail answers as GET. Concept and mapping details, source and collection version details, and a collection version's expansions list gave the view permission to GET only, so HEAD asked for edit access (403 for an outsider on a public source). HEAD now takes the view permission too. Where GET is refused (a private source or collection), HEAD is refused the same way.

  • The default expansion can't be deleted through resolved-repo-updates/. DELETE there fell through to the generic soft delete with no default-expansion check. The expansion base view now has one destroy that refuses the default expansion with the expansion DELETE's 400 ({'errors': ['Cannot delete default expansion']}). Each view keeps its own delete for any other expansion: a delete on the expansion, a soft delete on resolved-repo-updates/, as before.

  • Search parameters on the newly reachable fuzzy path (from the review passes). A fuzzy search's min_score that isn't a finite number answers 400, not 500. searchStatsOnly answers stats only on a searchable list with a search string left after quotes and spaces are stripped. Any other request answers as the list does without it, access check included. Before, q="" failed with a 500, and on a list that checks access in get_queryset the shortcut skipped that check.

Tests

Each new test fails on master:

  • CollectionReferenceAccessTest.test_reference_with_an_invalid_id_answers_404: abc, 30 and 5,000 digits, +id, 0_id and full-width digits, on both routes, for GET, HEAD and DELETE.
  • DetailHeadAccessTest: GET and HEAD give the same status for anonymous, outsider and member, public and private, on the five views. The private case already passes on master; it pins that HEAD stays refused.
  • FuzzySearchListsTest (es): fuzzy search on the global, source and collection mapping lists, and on a collection's concept list with and without includeSearchStats, answers 200 and returns only the list's own members.
  • FuzzySearchListsTest also covers min_score (high, nan, inf → 400) and a stats-only search for nothing, which answers as the list.
  • CollectionVersionExpansionResolvedRepoUpdatesViewTest: DELETE of the default expansion answers 400 and leaves it in place. A non-default one still answers 204.

For the reviewer

DELETE on resolved-repo-updates/ looks accidental: the class inherits DestroyAPIView, and the endpoint is a GET diff. If you'd rather it answer 405, that's a one-line change. This PR keeps it and adds the guard. Note that the soft delete it does for a non-default expansion changes nothing visible: nothing filters expansions on is_active, so the expansion stays listed and readable after the 204. That was already true on master.

Left open from the review passes, both already true on master: an unversioned collection search, plain or fuzzy, isn't limited to the default expansion (another item on the tracking ticket); and a stats-only search that Elasticsearch rejects answers 500, because the aggregation path doesn't translate search errors to 400 as the hits path does.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qWLYoaHjge22WUiaxG

…fuzzy search answers on mapping and collection lists, HEAD answers as GET on details, and default expansions stay

- A reference's detail URL answers 404 for an ID that isn't ASCII digits, or that
  no reference can have, as its concept and mapping lists already do. Both views
  share one helper.
- A fuzzy search on a mapping list, or on a collection's concept list, keeps to
  the URL's repository as plain search does. Only the source concept list sets
  fuzzy-search targets, and the other lists failed without them.
- HEAD on a concept, mapping, source version or collection version detail, and on
  a collection version's expansions, takes the view permission GET takes, not the
  edit permission.
- DELETE on an expansion's resolved-repo-updates answers 400 for the version's
  default expansion, as the expansion's own DELETE does. Both share one destroy;
  each keeps its own delete for any other expansion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWLYoaHjge22WUiaxG
@paynejd
paynejd requested a review from snyaggarwal November 24, 2026 06:01
@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.169.0, commit a62af97)

Verdict: findings: 1 P1, 1 P2.

  • F1.1 (P1) core/common/views.py:68: Fuzzy searches on the unversioned collection concept and mapping lists can return members of non-default expansions.
  • F1.2 (P2) core/common/views.py:1145: A malformed score threshold still produces HTTP 500 on fuzzy mapping searches.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "full",
  "commit": "a62af979",
  "verdict": "findings",
  "prior": [],
  "findings": [
    {
      "id": "F1.1",
      "severity": "P1",
      "tag": null,
      "file": "core/common/views.py",
      "line": 68,
      "claim": "Fuzzy searches on the unversioned collection concept and mapping lists can return members of non-default expansions.",
      "scenario": "Give a collection's HEAD a default expansion and a second expansion with a different matching concept. A fuzzy search on the collection's `/concepts/` route returns that second concept because the Elasticsearch scope filters by collection and HEAD but omits the default expansion URI. The explicit `/HEAD/concepts/` route applies that URI filter.",
      "action": "Scope fuzzy hits and search stats to the default expansion of the collection version the view resolved. Add a regression test with matching concepts in two expansions and verify both URL forms return only the default expansion's members.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F1.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1145,
      "claim": "A malformed score threshold still produces HTTP 500 on fuzzy mapping searches.",
      "scenario": "A request to `/mappings/?fuzzy=true&q=heart&min_score=high` reaches `float(min_score)` in the newly enabled fuzzy path. The uncaught `ValueError` produces HTTP 500.",
      "action": "Validate `min_score` before building the Elasticsearch query and return HTTP 400 for invalid values. Add a mapping-list regression test.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

… a finite number answers 400

The fuzzy search path read min_score with float(), so a value such as `high`
answered 500 on every list that runs a fuzzy search. A value that isn't a finite
number now answers 400, in the shape the pagination parameters use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWLYoaHjge22WUiaxG
@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Responses to Codex pass 1

  • F1.1 (P1), not fixed here. On master, plain search on the unversioned collection route already matches every expansion of HEAD: get_kwargs_filters adds expansion_url only when the URL names a version. This PR makes fuzzy search answer exactly as plain search does, nothing wider. Limiting both to the default expansion is a separate item on the tracking ticket and gets its own change.
  • F1.2 (P2), fixed in 54d8c00. A min_score that isn't a finite number (high, nan, inf) now answers 400, in the pagination parameters' shape. Test: FuzzySearchListsTest.test_fuzzy_search_with_a_min_score_that_isnt_a_number_answers_400; it fails on a62af97.

…rs an empty list

A query that is empty once quotes and spaces are stripped (`q=""`) builds no
search, and search stats then failed on it with a 500, fuzzy or not. Such a
search now answers [], as a search with no hits does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWLYoaHjge22WUiaxG
@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.169.0, commit 54d8c00)

Verdict: findings: 1 new P2. Earlier: F1.1 unresolved (left out of scope, see pass 1 responses), F1.2 resolved.

  • F2.1 (P2) core/common/views.py:1170: Stats-only fuzzy searches still return HTTP 500 when the query becomes empty after normalization.

Responses:

  • F2.1 (P2), fixed in 39b8341. On master this fails for plain search too, not only fuzzy: a query that is empty once quotes and spaces are stripped builds no search, and search stats called .extra() on nothing. Such a stats-only search now answers [], as one with no hits does. Test: FuzzySearchListsTest.test_stats_only_search_for_nothing_answers_an_empty_list (mapping, collection concept and source concept lists, fuzzy and plain); it fails on 54d8c00.
  • F1.1 (P1) stays out of scope, as answered after pass 1.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "54d8c00b",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "unresolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F2.1",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1170,
      "claim": "Stats-only fuzzy searches still return HTTP 500 when the query becomes empty after normalization.",
      "scenario": "`GET /mappings/?fuzzy=true&searchStatsOnly=true&q=%22%22` enters the stats branch because the raw query contains two quote characters. Search removes the quotes and returns no Elasticsearch query, so aggregation calls `.extra()` on `None`. The collection concept list has the same failure.",
      "action": "Return HTTP 400 when a stats-only request has an empty normalized query, and add a regression test for both lists.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

…ere a search runs; elsewhere the list answers as without it

The stats-only shortcut ran before a view's own access check, so on a list
that keeps that check in get_queryset (a collection version's expansions) a
GET answered 200 where HEAD answered 403, and with a real query it failed
there with a 500. It now runs only on a searchable list with a search string
left after quotes and spaces are stripped. Any other request answers as the
list does without searchStatsOnly, access check included. This replaces the
empty-stats answer from the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWLYoaHjge22WUiaxG
@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.169.0, commit 39b8341)

Verdict: findings: 2 new P2. Earlier: F1.1 unresolved (out of scope, see pass 1 responses), F1.2 and F2.1 resolved.

  • F3.1 (P2) core/collections/views.py:961: A private collection version's expansions list can answer 200 to GET while refusing HEAD.
  • F3.2 (P2) core/common/views.py:1353: A stats-only fuzzy mapping search can still turn invalid search input into HTTP 500.

Responses:

  • F3.1 (P2), fixed in a8ded90. The stats-only shortcut ran before a view's own access check. It now runs only on a searchable list with a search string left after quotes and spaces are stripped; any other request answers as the list does without searchStatsOnly, access check included. This replaces 39b8341's empty-stats answer, so F2.1's q="" case now answers as the list. Tests: DetailHeadAccessTest.test_head_on_a_private_detail_is_refused_as_get_is (expansions list with searchStatsOnly) and FuzzySearchListsTest.test_stats_only_search_for_nothing_answers_as_the_list; both fail on 39b8341.
  • F3.2 (P2), accepted. On master every stats-only search fails this way, plain or fuzzy and on every list: the aggregation path never got the hits path's Elasticsearch error translation. Sharing that translation is a separate change, left out of this PR.
findings.json
{
  "reviewer": "codex-cli 0.169.0",
  "perspective": "defects",
  "mode": "verify",
  "commit": "39b8341f",
  "verdict": "findings",
  "prior": [
    {
      "id": "F1.1",
      "status": "unresolved"
    },
    {
      "id": "F1.2",
      "status": "resolved"
    },
    {
      "id": "F2.1",
      "status": "resolved"
    }
  ],
  "findings": [
    {
      "id": "F3.1",
      "severity": "P2",
      "tag": null,
      "file": "core/collections/views.py",
      "line": 961,
      "claim": "A private collection version's expansions list can answer 200 to GET while refusing HEAD.",
      "scenario": "An outsider requests the expansions list with searchStatsOnly=true and a whitespace-only q. The GET stats branch now returns 200 with [] before get_queryset checks the version's permissions. HEAD reaches that check and returns 403.",
      "action": "Check the version's read permission before the list mixin can return early. Add this request to the GET and HEAD parity test.",
      "lines_delta": null,
      "confidence": "high"
    },
    {
      "id": "F3.2",
      "severity": "P2",
      "tag": null,
      "file": "core/common/views.py",
      "line": 1353,
      "claim": "A stats-only fuzzy mapping search can still turn invalid search input into HTTP 500.",
      "scenario": "A /mappings/ request with fuzzy=true, a nonempty q, and searchStatsOnly=true sends an oversized mapType wildcard filter. Elasticsearch rejects the generated regular expression, and the aggregation path lets the error escape. The hits path already translates that error to HTTP 400. [Elasticsearch regexp query limits](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/query-dsl-regexp-query.html)",
      "action": "Apply the hits path's request-error translation to aggregation execution and assert HTTP 400 in a stats-only mapping regression test.",
      "lines_delta": null,
      "confidence": "high"
    }
  ]
}

@paynejd

paynejd commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Simplification review (Claude Sonnet 5.5 subagent, commit a8ded90)

Four suggestions; none applied.

  • S1 (shrink, min_score parse), kept. The suggested form is no shorter, and the current one has a single raise path.
  • S2 (dup-test, bare ?fuzzy=true), kept. That request, with no q, is the exact URL in the acceptance criteria.
  • S3 (shrink, stats-only spellings), kept. "", '' and a space each go through a different normalization step, and the fuzzy=false axis covers plain search, which failed the same way.
  • S4 (dup-test, searchStatsOnly URLs in the private HEAD test), kept. They're the only test that pins the pass 3 F3.1 fix (GET and HEAD refused alike on a private expansions list).

This branch has not been deployed

No deployments
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.

1 participant