|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from enum import Enum |
4 | 5 | from typing import TYPE_CHECKING, Any, Iterable, List, Literal, Union |
5 | 6 |
|
|
9 | 10 | if TYPE_CHECKING: |
10 | 11 | from typing_extensions import TypeAlias |
11 | 12 |
|
| 13 | +logger = logging.getLogger(__name__) |
| 14 | + |
12 | 15 |
|
13 | 16 | class ConditionParserError(ValueError): |
14 | 17 | """Raised when unable to determine the Condition type from a dict.""" |
@@ -81,6 +84,31 @@ class Column(BaseModel): |
81 | 84 | def __init__(self, name: str): |
82 | 85 | super().__init__(name=name) |
83 | 86 |
|
| 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 | + |
84 | 112 | @override |
85 | 113 | def __hash__(self) -> int: |
86 | 114 | return hash(self.name) |
|
0 commit comments