Skip to content

Fix SQLAlchemy 2 reflection and validate release artifacts (Workflow A fallback for upstream #100) - #1

Merged
aminghadersohi merged 5 commits into
masterfrom
workflow-a-sqlalchemy2-reflection-security
Sep 16, 2026
Merged

aminghadersohi merged 5 commits into
masterfrom
workflow-a-sqlalchemy2-reflection-security

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

What this is

A Preset-owned fallback for the SQLAlchemy 2 Drill dialect fixes. This is the byte-identical reviewed head of upstream JohnOmernik/sqlalchemy-drill#100 — commit ca7ace9eebe769bea3e620db60ba32906b67f95a, pushed here unmodified.

Upstream JohnOmernik#100 remains OPEN and is the preferred landing path. This PR exists only because upstream CI has never executed: its workflow run sits at action_required with zero jobs behind the fork-PR approval gate, and no upstream admin has been available to approve it (last upstream activity: 2026-02-05). Nothing here supersedes or abandons JohnOmernik#100.

Attribution and history

This repository is a fork of JohnOmernik/sqlalchemy-drill, so the full upstream history is intact. All five commits retain their original authorship and dates — nothing was squashed, rebased, amended, or cherry-picked. master here is 632c44b, identical to upstream master, so the diff is exactly the five reviewed commits and nothing else.

Original project: JohnOmernik/sqlalchemy-drill, MIT licensed. Prior contributors to the touched code include @cgivre, @jnturton, and @potiuk.

What it fixes

  • Identifier quoting under SQLAlchemy 2
  • Schema-qualified table compilation
  • Native JDBC/ODBC/REST import_dbapi hooks
  • REST parameter and comment-substitution edge cases, including Drill comment-grammar lexing
  • Bounded reflection probes that no longer silently cache REST failures
  • Release-pipeline hardening: single-sourced version metadata and fail-closed wheel/sdist artifact checks

Verification

Full test.yml reproduced against this exact sha, both in CI and locally against a real pinned Apache Drill container:

Check Result
SQLAlchemy 1.4.54 112 passed, 1 version-specific skip
SQLAlchemy 2.0.52 113 passed
SQLAlchemy 2.1.0rc1 113 passed
Drill REST integration (real testcontainer) 137 passed, 4 skipped
Artifact gate 25 passed
twine check --strict PASSED (wheel + sdist)
Clean-venv wheel install 88 passed
Clean-venv sdist install 88 passed

Declared version is 1.1.11, single-sourced from the package. CodeQL is the one check not reproduced — it is disabled_inactivity upstream.

Not ready to merge

Deliberately not merged, tagged, or published. Artifact version/provenance and the trusted-publishing mechanism must be verified first. No release has been cut and no credential has been used.

Provenance notes (read before any publication)

  • Declared version is 1.1.11, single-sourced from sqlalchemy_drill/__init__.py and read by setup.py without importing the package.
  • 1.1.11 does not exist on public PyPI. The latest public release is 1.1.10, and the latest upstream tag/release is v1.1.10 (2026-02-05). Publishing 1.1.11 anywhere therefore creates a version that has no upstream counterpart — see the supply-chain caveat tracked alongside this PR.
  • Package metadata deliberately retains the upstream Home-page and the original author list (John Omernik, Charles Givre, Davide Miceli, Massimo Martiradonna, James Turton). License is MIT, unchanged.

Use SQLAlchemy executable metadata queries with bound values, quote Drill identifiers, render compatible column qualifiers, and fix transport-local DBAPI hooks. Harden REST qmark substitution without reinterpreting literals or comments. Preserve invalidated-connection errors during has_table.

Prepare unreleased version 1.1.11 from one source; exclude runtime test packages, complete the sdist, and reject every unexpected artifact or mismatched metadata before clean-install tests and OIDC publication. Preserve upstream trusted publishing. JDBC/ODBC, TLS, and downstream production images remain unqualified.
Do not infer table absence from opaque dynamic-query failures. Preserve SQLAlchemy schema translation quote flags, require sdist compliance dependencies, assert every executemany call, and describe upstream rather than intermediate-candidate behavior in the changelog.
@fitzee

fitzee commented Sep 16, 2026

Copy link
Copy Markdown

Adversarial code review (head ca7ace9)

Large, well-tested PR — the qmark-substitution regex, schema-translation token handling, and _sql_literal type dispatch all held up under scrutiny. Five issues survived verification:

1. has_table regression for mongo/splunk plugins — sqlalchemy_drill/base.py:431

The old has_table always fell back to get_columns(). The rewrite only falls back for plugin_type == 'file'; for mongo/splunk it returns False as soon as INFORMATION_SCHEMA.TABLES has no row. A queryable mongo/splunk collection not enumerated in INFORMATION_SCHEMA.TABLES now reports absent, breaking Table(autoload_with=...) and create_all(checkfirst=True) — and it's inconsistent with get_columns(), which still succeeds on the same name.

2. Sub-second datetime/time literals violate Drill's stated format — sqlalchemy_drill/drilldbapi/_drilldbapi.py:113

_sql_literal renders microseconds ('2020-01-02 03:04:05.123456', time().isoformat()), but the code's own comments say Drill requires exactly yyyy-MM-dd HH:mm:ss. A CAST(:value AS TIMESTAMP/TIME) on a microsecond-bearing value can raise DateTimeParseException server-side. Integration tests only exercise microsecond-free values; the microsecond path is checked only by a local string-rendering unit test, never against Drill.

3. Divergent reflection metadata between branches — sqlalchemy_drill/base.py:530

The file/mongo/splunk branch returns column key "longtype" (lowercase) and omits "nullable"; the INFORMATION_SCHEMA branch returns "longType" plus "nullable". Callers get different metadata purely by plugin type, and this PR widened the gap by adding nullable to only one branch.

4. Raw ValueError on malformed schema paths — sqlalchemy_drill/base.py:202

_schema_parts raises ValueError('Drill schema paths cannot contain empty components') for any empty component (e.g. schema='cp.', 'dfs..tmp', or a URL like drill+sadrill://host/dfs.). Since quote_schema()/format_table() run on every schema-qualified statement, this surfaces as an opaque error during compilation instead of a clean dialect error.

5. Dead dialect registrations in tests — test/conftest.py:37

conftest.py registers drill.pyodbc → sqlalchemy_drill.pyodbc and drill.pydrill → sqlalchemy_drill.pydrill, but the package ships only sadrill, jdbc, and odbc — no such modules exist. Any create_engine('drill+pyodbc://...')/'drill+pydrill://...' in tests fails with ModuleNotFoundError; the registrations are dead and misleading.


Not merge-blockers on their own, but #1 (mongo/splunk has_table regression) and #2 (microsecond format) are the two worth addressing or explicitly acknowledging before merge.

🤖 Generated with Claude Code

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.

2 participants