Skip to content

chore(lint): query in database tests is checked against the schema - #723

Draft
PiquelChips wants to merge 1 commit into
mainfrom
chore/ban-query-function
Draft

PiquelChips wants to merge 1 commit into
mainfrom
chore/ban-query-function

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What and why

Last of three PRs that move SQL to the checked macros. sqlx::query (the function, which checks nothing) is now banned in clippy.toml. 53 of its 60 sites are sqlx::query!, with their statements in the committed query cache (just db prepare). Only crates/database used it; its production code already used the macros apart from one DDL helper.

Six #[expect(clippy::disallowed_methods)] cover the other seven sites, each on a function or for statement, because the statement is not known at compile time:

  • AuditRepository::guards: ALTER TABLE formatted from literals; DDL takes no bind parameters.
  • runtime_role_has_only_row_privileges and assert_personal_data_only_erases (connection tests): each listed statement, DDL and COPY included, runs as the runtime role to see it refused or allowed.
  • assert_history_is_never_forged (connection tests): the statement goes to refusal, which takes a prepared statement, and a payload is bound as text where query! expects jsonb.
  • attempt (audit tests): callers pass each guarded statement.
  • the SET clause loop of the email ownership test.

Two statements changed shape with query!: a bare SELECT becomes fetch_all/fetch_optional with a ! alias (execute is for statements without columns), and pg_sleep and pg_advisory_xact_lock select from the function, since query! cannot describe void. The refresh-token lock probe lists its three statements in a match instead of a loop.

Testing

just db test passes (509 tests, then the query cache check), and cargo clippy --workspace --all-targets -- -D warnings passes.

Note

Written by Claude Sonnet 5.5 in Claude Code (via T3 Code)

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

1 participant