Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Restore CKAN standard-variable autocomplete: label_contains + enable_ckan - #9

Merged
mosoriob merged 1 commit into
mainfrom
fix/standardvariables-ckan-autocomplete
Aug 29, 2026
Merged

Restore CKAN standard-variable autocomplete: label_contains + enable_ckan#9
mosoriob merged 1 commit into
mainfrom
fix/standardvariables-ckan-autocomplete

Conversation

@mosoriob

Copy link
Copy Markdown
Contributor

Problem

The CKAN dataset form autocompletes MINT standard variables against this API. It is broken in production.

The widget was built against the v1.8.0 FastAPI catalog. Two behaviours it depends on were not ported to this service:

  • label filters with _eq. A partial term matches nothing, so a suggestion only appears once the user types the entire variable name.
  • enable_ckan does not exist. The response is the plain JSON-LD array. CKAN's parseCompletions reads item.name || item.Name || item.Format; our rows carry none of those, so every suggestion collapses to an empty string.

Measured against production before the fix:

label=a                        -> 0
label=land_surface_wind        -> 0
label=land_surface_wind__spee  -> 0
label=land_surface_wind__speed -> 1

Change

Two new query params on the generic list handler, both opt-in.

label_contains=<term> builds label: { _ilike: "%term%" }. % and _ in the term are escaped so they match literally. This matters: standard variable labels are underscore-heavy (land_surface_wind__speed), and an unescaped _ is a single-character wildcard in Postgres, which would make the search quietly wrong rather than obviously broken.

enable_ckan=true projects the result into {"ResultSet": {"Result": [{"Name": "..."}]}}.

label keeps its exact-match behaviour, so existing callers are unaffected.

Note on the API-design choice

I added a separate param rather than widening label to a substring match. label is live on a deployed API with consumers I cannot enumerate, and there was a test pinning _eq. Turning every resource's exact filter into a substring match seemed like the wrong trade for a fix aimed at one widget. Happy to collapse the two if you would rather label just do substring.

Why the openapi.yaml change is required

Both params are declared on /standardvariables. This is not only for docs: fastify-openapi-glue validates the querystring and AJV strips undeclared params before the handler runs. Implementing them without declaring them would compile, pass every service-level test, and still do nothing in production.

Tests

npm test — 134 passed, 38 skipped (was 130). npm run build clean.

15 new tests across two levels:

  • src/__tests__/integration.test.ts — filter construction, wildcard escaping, label + label_contains combined, response shaping, enable_ckan=false not treated as truthy.
  • src/__tests__/standardvariables-ckan-route.test.ts (new) — goes through the real Fastify router with Hasura mocked, covering the AJV stripping and the boolean coercion that a direct service call bypasses.

Deploying this

The CKAN side needs a matching one-line change, pointing its autocomplete at label_contains=? instead of label=? (ckanext-dso_scheming/mint_presets.json, in the ckan-docker repo). That change is prepared but not yet merged. The CKAN form stays broken until this is deployed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh9z6U8JosPJnGqPNQf3fk

…autocomplete

CKAN's dataset form autocompletes MINT standard variables against this API.
That widget broke when the catalog moved from the v1.8.0 FastAPI service to
this one, because two behaviours it relied on were never ported:

- `label` filters with `_eq`, so a partial term matched nothing. The widget
  only returned a suggestion once the user typed the entire variable name.
- `enable_ckan` did not exist, so the response was the plain JSON-LD array.
  CKAN's `parseCompletions` reads `item.name || item.Name || item.Format`,
  none of which our rows carry, so every suggestion collapsed to "".

Add both without changing existing semantics:

- `label_contains=<term>` builds `label: { _ilike: "%term%" }`. `%` and `_`
  are escaped so they match literally -- standard variable labels are full of
  underscores (`land_surface_wind__speed`), and an unescaped `_` would act as
  a single-character wildcard.
- `enable_ckan=true` projects the result into
  `{"ResultSet": {"Result": [{"Name": "..."}]}}`.

`label` keeps its exact-match behaviour, so existing callers are unaffected.

Both params are declared on /standardvariables in openapi.yaml -- required,
not just for docs: fastify-openapi-glue validates the querystring and AJV
strips undeclared params before the handler sees them.

Tested at the service level and through the real router, the latter to cover
the AJV stripping and boolean coercion that a direct service call bypasses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh9z6U8JosPJnGqPNQf3fk
mosoriob pushed a commit to mintproject/mint that referenced this pull request Aug 28, 2026
* chore(model-catalog-api): pin image to the CKAN autocomplete fix

Deploys mintproject/model-catalog-api#9, which restores the standard
variable autocomplete on the CKAN dataset form. That widget has been
returning no suggestions since the catalog moved off the v1.8.0 FastAPI
service: `label` filtered with `_eq` so partial terms matched nothing, and
`enable_ckan` did not exist so CKAN could not read the response shape.

Pin the tag to the commit SHA rather than leaving it on `latest`. This is
what most images in values.yaml already do, and it makes the rollout
explicit instead of depending on when a pod happens to restart.

Chart version bumped so `ct lint` accepts the change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh9z6U8JosPJnGqPNQf3fk

* update Helm documentation

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@mosoriob
mosoriob merged commit 6660f48 into main Aug 29, 2026
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant