Skip to content

BUG: get_columns() incorrectly reports all column types due to a late-binding closure bug #82

Closed

Description

@arin-balyan1

BUG: get_columns() incorrectly reports all column types due to a late-binding closure bug

Summary

The get_columns() implementation in the e6data SQLAlchemy dialect incorrectly reports the data type of every reflected column. Instead of returning each column's actual SQL type, all columns are assigned the data type of the last column in the table.

This breaks SQLAlchemy schema reflection and affects downstream tools such as Great Expectations that rely on accurate column metadata.

Root Cause

The issue is caused by a Python late-binding closure bug:

for column in columns:
    row = {}
    row["name"] = column.get("fieldName")
    row["type"] = lambda: column.get("fieldType")
    rows.append(row)

Since the lambda captures the column variable by reference, all lambdas eventually point to the last element in the loop. As a result, every reflected column is assigned the type of the last column.

Example

Given the following table:

Column | Actual Type -- | -- id | INTEGER name | VARCHAR salary | DOUBLE created_at | TIMESTAMP

Expected reflection:

id          -> INTEGER
name        -> VARCHAR
salary      -> DOUBLE
created_at  -> TIMESTAMP

Actual reflection:

id          -> TIMESTAMP
name        -> TIMESTAMP
salary      -> TIMESTAMP
created_at  -> TIMESTAMP

Impact

Because all columns are reflected with the same type, downstream tools such as Great Expectations are unable to correctly infer the schema. This prevents schema creation and causes several type-based validations and other reflection-based features to fail.

Additionally, the current implementation bypasses the existing _type_map, returning raw e6data type strings instead of mapping them to the corresponding SQLAlchemy types.* objects.

Proposed Fix

I've identified the root cause and implemented a fix that:

  • Resolves the late-binding closure issue.

  • Uses the existing _type_map to return the appropriate SQLAlchemy type objects.

The proposed fix has already been submitted for review in Pull Request #81.

Activity

  1. vishale6x commented on Jun 29, 2026

    @vishale6x
    Contributor

    Fixed in #83, now merged into main and released as 2.3.14.

    The fix resolves the late-binding closure in get_columns() — each reflected column now resolves its type independently and maps through the existing _type_map to the correct SQLAlchemy types.* object (falling back to types.String for unknown types). A regression test (test/test_dialect_columns.py) guards against this recurring.

    Note: the original PR #81 referenced here has been closed in favor of #83, which carries the same fix plus the regression test and SQLAlchemy version-compatibility shims.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions