Skip to content

fix(validation): degrade gracefully on sqlglot older than 30.19.0 - #780

Merged
christianeu-db merged 1 commit into
apache:mainfrom
christianeu-db:fix-validate-sqlglot-agg-version-guard
Nov 21, 2026
Merged

christianeu-db merged 1 commit into
apache:mainfrom
christianeu-db:fix-validate-sqlglot-agg-version-guard

Conversation

@christianeu-db

Copy link
Copy Markdown
Contributor

Summary

validation/validate.py references exp.Agg, a sqlglot expression class that
exists only in sqlglot >= 30.19.0 (added together with the AGG() support
in #703 / #726). The script's inline metadata pins that minimum, so uv run
works. However, running the script as a plain python validation/validate.py <file> uses whatever sqlglot is already on the path. An older sqlglot imports
cleanly (SQLGLOT_AVAILABLE = True), then crashes mid-validation at the first
tree.find_all(exp.Agg):

AttributeError: module 'sqlglot.expressions' has no attribute 'Agg'

This PR makes the validator degrade gracefully instead of crashing, matching
the existing behavior for when sqlglot is not installed at all:

  • Detect a too-old sqlglot at import (not hasattr(exp, "Agg")) and treat it
    as unavailable, so every existing not SQLGLOT_AVAILABLE guard skips the SQL
    checks.
  • Emit one clear ValidationWarning in validate_document naming the
    installed version, the required minimum, and an upgrade hint.
  • Suppress the two existing "sqlglot not installed" warnings in that case,
    since the sqlglot is installed, only too old.

No behavior change for the supported configuration (sqlglot >= 30.19.0).

Related Issues

Checklist

Validation

  • New validation cases are covered by tests

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

This pull request and its description were written by Isaac.

validate.py references exp.Agg, which sqlglot ships only from 30.19.0.
Running the script with an older sqlglot already on the path (a plain
`python validate.py` run rather than `uv run`) raised AttributeError
mid-validation.

Detect the too-old version at import, treat it as unavailable so the
existing SQL-check guards skip cleanly, and emit one clear warning naming
the required minimum instead of crashing. The two existing "sqlglot not
installed" warnings are suppressed in that case, since the sqlglot is
installed, only too old.

Co-authored-by: Isaac <no-reply@databricks.com>
@christianeu-db
christianeu-db force-pushed the fix-validate-sqlglot-agg-version-guard branch from 16a9a71 to 69ed8cf Compare November 20, 2026 18:37
@christianeu-db
christianeu-db marked this pull request as ready for review November 20, 2026 18:39
@christianeu-db
christianeu-db requested review from jbonofre and kayemkim and removed request for kayemkim November 20, 2026 19:24

@kayemkim kayemkim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this as plain python validation/validate.py against real sqlglot releases, since the test only patches the two flags. 30.18.0 and older releases back to 20.0.0 print the one warning and pass the examples where main stops with the AttributeError, and 30.19.0 runs the SQL checks as before. The ontology and mapping documents get the same single warning. LGTM.

@christianeu-db
christianeu-db merged commit 0f579ad into apache:main Nov 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants