Skip to content

fix(store): support all RQL schema fields in SearchOrganizations filters - #2065

Open
0xABCD01 wants to merge 1 commit into
raystack:mainfrom
0xABCD01:fix/1979-search-orgs-name-filter
Open

0xABCD01 wants to merge 1 commit into
raystack:mainfrom
0xABCD01:fix/1979-search-orgs-name-filter

Conversation

@0xABCD01

@0xABCD01 0xABCD01 commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1979. SearchOrganizations answered internal (500) when a query filtered on name, even though name is a valid field of the AggregatedOrganization RQL schema and passes handler validation. The store's own filter allow-list was missing six of the fields the schema exposes, and the error it returned for an unsupported filter was a plain error, so the handler could not map it to invalid_argument.

Changes

  • Add the missing schema fields to the filter allow-list in addRQLFiltersInQuery (internal/store/postgres/org_billing_repository.go): name, created_by, country, avatar, plan_id (strings) and updated_at (datetime). The allow-list now matches the RQL schema exactly.
  • Wrap the unsupported-filter error in postgres.ErrBadInput, so any filter the store still cannot serve maps to invalid_argument in the handler instead of internal.
  • Add TestPrepareDataQuery_SchemaFieldsFilterable covering each added field and the ErrBadInput mapping.

Technical Details

The added fields resolve against the columns the search subquery (ranked_subscriptions) already selects, so no query shape changes: string fields go through the existing processStringDataType handling and updated_at through the existing datetime branch, same as the already-supported fields.

Test Plan

  • Manual testing completed
  • Build and type checking passes

New regression test TestPrepareDataQuery_SchemaFieldsFilterable: an eq filter on each added string field, a gt filter on updated_at, and an unsupported field asserting the error wraps ErrBadInput. On the unpatched code every added-field case fails with addRQLFiltersInQuery: <field> is not supported in filters; with the fix the new test plus the existing TestPrepareDataQuery/TestPrepareGroupByQuery suites pass (go vet clean). The package's dockertest-backed suites need Docker and were not run in my sandbox; the query-builder unit tests above need no database.

SQL Safety (if your PR touches *_repository.go or goqu.*)

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed. (Unchanged mechanism; a filter name is only used as an identifier after matching the constant allow-list.)
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L (use make_interval(hours => ?)-style functions instead).
  • Any //nolint:forbidigo or // #nosec G20x annotation has a one-line justification on the same line that a reviewer can verify. (None added.)

@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

@0xABCD01 is attempting to deploy a commit to the Raystack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e33f29 and c711b56.

Files selected for processing: 2

  • internal/store/postgres/org_billing_repository.go
  • internal/store/postgres/org_billing_repository_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

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.

SearchOrganizations answers internal when filtering on name

1 participant