Skip to content

Commit 519042e

Browse files
committed
fix error
1 parent 40a14b2 commit 519042e

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

great_expectations/expectations/conditions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from enum import Enum
45
from typing import TYPE_CHECKING, Any, Iterable, List, Literal, Union
56

@@ -9,6 +10,8 @@
910
if TYPE_CHECKING:
1011
from typing_extensions import TypeAlias
1112

13+
logger = logging.getLogger(__name__)
14+
1215

1316
class ConditionParserError(ValueError):
1417
"""Raised when unable to determine the Condition type from a dict."""
@@ -81,6 +84,31 @@ class Column(BaseModel):
8184
def __init__(self, name: str):
8285
super().__init__(name=name)
8386

87+
@validator("name", pre=True)
88+
@classmethod
89+
def _parse_column_name(cls, v: str) -> str:
90+
"""Parse column names that contain the col("...") syntax.
91+
92+
This handles cases where conditions are deserialized from GX Cloud with
93+
unparsed column names like 'col("DeltaReturn10Year")' instead of the
94+
clean name 'DeltaReturn10Year'.
95+
96+
Args:
97+
v: The column name string, potentially containing col() syntax
98+
99+
Returns:
100+
The clean column name without col() wrapper
101+
"""
102+
if isinstance(v, str) and v.startswith('col("') and v.endswith('")'):
103+
# Extract just the column name from col("name") syntax
104+
clean_name = v[5:-2] # Remove 'col("' from start and '")' from end
105+
logger.debug(
106+
f"Parsed unparsed column name from '{v}' to '{clean_name}'. "
107+
"Column names should be provided without col() wrapper."
108+
)
109+
return clean_name
110+
return v
111+
84112
@override
85113
def __hash__(self) -> int:
86114
return hash(self.name)

great_expectations/expectations/metrics/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,10 +1695,15 @@ def get_sqlalchemy_column_metadata( # noqa: C901 # FIXME CoP
16951695
schema=schema_name,
16961696
)
16971697
else:
1698-
logger.warning("unexpected table_selectable type")
1699-
columns = inspector.get_columns( # type: ignore[assignment]
1700-
table_name=str(table_selectable),
1701-
schema=schema_name,
1698+
# For Select, Subquery, or other SQLAlchemy constructs (e.g., when row conditions are applied),
1699+
# we cannot use inspector.get_columns() as they are not simple table names.
1700+
# Raise an exception to trigger the fallback mechanism that uses column reflection.
1701+
logger.debug(
1702+
f"table_selectable is of type {type(table_selectable).__name__}, "
1703+
"using column reflection fallback"
1704+
)
1705+
raise AttributeError(
1706+
"Cannot introspect columns from complex query; using reflection fallback"
17021707
)
17031708
except (
17041709
KeyError,

0 commit comments

Comments
 (0)