Skip to content

Type endpoint parameters and bind them into project DB SQL - #38096

Draft
MartinRiese wants to merge 5 commits into
masterfrom
riese/cs_endpoints_typed_params
Draft

Type endpoint parameters and bind them into project DB SQL#38096
MartinRiese wants to merge 5 commits into
masterfrom
riese/cs_endpoints_typed_params

Conversation

@MartinRiese

Copy link
Copy Markdown
Contributor

Product Description

Technical Summary

Feature Flag

Safety Assurance

Safety story

Automated test coverage

QA Plan

Migrations

  • The migrations in this code can be safely applied first independently of the code. Pay particular attention to backward incompatible operations like RemoveField, RenameField, RemoveConstraint, and others described here that can cause errors when migrations are applied to a live database.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

MartinRiese and others added 5 commits August 31, 2026 16:44
With '' queries like
(:weight IS NULL OR number_prop__weight > :weight)

Fail on

invalid input syntax for type numeric: ""
LINE 3: ...D ('' = '' OR projectdb_mriese.pet.number_prop__weight > '')
Adds a daterange parameter type and the two functions that map a search
request onto the placeholders an endpoint's SQL leaves unbound.

daterange is parameter-only: no case property has that type, so it has no
operations and the existing slot-type check rejects it in an Elasticsearch
query spec without needing a special case. It derives two placeholders,
:<name>_from and :<name>_to, which parse_parameter_spec now guards against
colliding with another parameter's name.

bind_values decides arity from the declared type rather than from what was
searched for, so an endpoint's SQL works whatever arrives: a select
parameter is always a list, everything else always a scalar, and multiple
values for a scalar are a user error rather than a 500 out of psycopg2.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
get_project_db_results now binds through the endpoint's parameter spec
instead of passing every placeholder the raw criterion value. Date ranges
and multi-select criteria reach Postgres in a shape it can use, where
before they arrived as '__range__...' or a Python list and failed as an
uncaught DataError.

A project DB endpoint must now declare the parameters its SQL references.
The spec is validated when the endpoint is saved, so a stored spec that
does not parse is reported as a bug rather than as the searcher's fault.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reports at save time what would otherwise fail when the endpoint runs: a
placeholder the spec does not declare, or a declared parameter the SQL
never uses, both of which UserSQL.run rejects as BadParameters.

Two shape checks come from the compiled binds. A parameter used with IN
renders nothing at all when unsupplied, so its NULL guard raises an
IndexError out of psycopg2 rather than anything a caller can report. And
a select parameter holds a list, so it has to be compared with a
select_prop__ array column using && or @> -- comparing a list against a
text column is an "operator does not exist" error, and a bare string
against an array column silently matches nothing.

UserSQL grows parameter_binds, exposing what parameters already computed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds the daterange and select options, both gated to project DB endpoints
since neither has an operation in the query builder, and shows the
placeholder names each parameter derives so a daterange's :<name>_from and
:<name>_to are visible rather than documented elsewhere.

The SQL card gains a note on guarding parameters with IS NULL and on
comparing a select parameter against a select_prop__ column.

The README covered only Elasticsearch endpoints, so it gains the binding
rules and a section on the project DB target.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MartinRiese
MartinRiese force-pushed the riese/cs_endpoints_number_param branch from a72893a to 0225f4a Compare September 2, 2026 18:42
Base automatically changed from riese/cs_endpoints_number_param to master September 3, 2026 11:34
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