Skip to content

SqlQuery should accept sqlglot exp.Expr (exp.Query isn't an exp.Expression in sqlglot 30) #56

Closed

Description

@aersam

pgdevkit.db.fetch.SqlQueryNoTemplate/SqlQuery use exp.Expression for sqlglot queries. In sqlglot 30 the class hierarchy is split: exp.Query (the base of Select, Union, Subquery, ...) is an exp.Expr but not an exp.Expression (issubclass(exp.Query, exp.Expression) is False, issubclass(exp.Query, exp.Expr) is True; a concrete Select is both).

Impact (found in the CCMT2 rollout): code that has an exp.Query-typed value (e.g. the return type of a query builder, or a Union) cannot pass it to fetch_all/fetch_one/fetch_scalar/execute/PostgresJsonResponse without failing pyright/ty; CCMT2 worked around it by rendering to text and passing that. Runtime is fine (_render only needs .sql(dialect=...) and .walk()).

Fix: widen the annotation to exp.Expr (it's the common base in sqlglot >= 30; check what the minimum supported sqlglot version offers, and fall back to exp.Expression on older ones if needed) and add a type-level test (or a runtime test with a Union) so it doesn't regress.

Claude Session: dd3520fe-363b-5088-ab76-5e87fad68be0

Activity

  1. added
    bugSomething isn't working
    pr-availableA PR exists that addresses this issue
    on Oct 9, 2026
  2. aersam commented on Oct 9, 2026

    @aersam
    ContributorAuthor

    Working on this in PR #57 (Claude session dd3520fe-363b-5088-ab76-5e87fad68be0).

  3. aersam commented on Oct 9, 2026

    @aersam
    ContributorAuthor

    PR #57 is ready for review and CI is green: the sqlglot query annotation is now exp.Expr, so exp.Query values (Select/Union/Subquery) are accepted by fetch_all/fetch_one/fetch_scalar/execute/PostgresJsonResponse. Runtime tests cover Union/Subquery and nested Command/placeholder rejection. Version 0.15.2.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpr-availableA PR exists that addresses this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions