fix(api): Reject query operands the column cannot take (backport #925) - #932
Conversation
A filter operand that does not match its column type reached Postgres
verbatim and the driver error surfaced to the client as a 500:
GET /projects?q=creation_time=[a~b]
-> 500, core: invalid input syntax for type timestamp: "a"
Same for /audit-logs?q=op_time=[x~y] and artifacts ?q=push_time=[2020~abc],
and for exact matches and or-lists against integer columns.
Record each model field type while parsing the model metadata and check
the operand against it before the filter is applied, returning a bad
request instead. The check is deliberately permissive so nothing that
works today stops working: text columns take any literal, number columns
take numerics within the column's own width, timestamp columns take the
documented format and the other forms Postgres reads, booleans take the
full Postgres token set, and fuzzy matches and __icontains are exempt
because both render as ILIKE, which casts the column to text.
Clean backport of the merged a39a4d7, which is #874 plus the review
fixups that landed on it. Replaces #909, which carried the superseded
#874 commit.
Signed-off-by: Prasanth Baskar <prasanth@8gears.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Preview images for this PR are available in
Verify a preview image: Verify SBOM attestation: |
Backport of #925 to
release-2.15. Replaces #909, which carried the superseded #874 commit.A search filter whose value did not fit the column returned 500, leaking the raw Postgres error. It should be 400.
What changed
Filter values are checked against the column's type before the query is built, and a mismatch returns 400 instead of reaching the database. This covers every endpoint that filters through
orm.QuerySetter.The check is deliberately permissive, so queries that work today keep working:
__icontainsare exempt, since they search as text2020-04-09 02:36:00format plus the other forms Postgres acceptsyes,onandnRelationship to #909
#909 backported #874, which was closed and continued as #925 after picking up review fixups — column-width checks, the boolean token set, the
__icontainsexemption, and a corrected DB test case. Rather than retrofit #909 in place, this is a fresh branch cut from the merged commit so the content is exactly what landed onmain.How it was produced
Cherry-pick equivalent of a39a4d7, the squashed merge of #925. All five touched files were byte-identical between
release-2.15and a39a4d7's parent before the pick, so nothing release-specific was overwritten.How it was verified
Built against the
release-2.15base, withlib/ormandlib/qgreen and the db-taggedpkg/project/daofilter-value suite passing against a freshly migrated Postgres on this branch: