Skip to content

Commit d2322d6

Browse files
committed
Adjust implementation to make tests pass
1 parent eee9300 commit d2322d6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

sqlmesh/core/model/meta.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
field_validator,
4040
list_of_fields_validator,
4141
model_validator,
42+
get_dialect,
4243
)
4344

4445
if t.TYPE_CHECKING:
@@ -182,12 +183,20 @@ def _gateway_validator(cls, v: t.Any) -> t.Optional[str]:
182183
def _partition_and_cluster_validator(
183184
cls, v: t.Any, info: ValidationInfo
184185
) -> t.List[exp.Expression]:
185-
if isinstance(v, list) and info.field_name == "partitioned_by_":
186+
if (
187+
isinstance(v, list)
188+
and all(isinstance(i, str) for i in v)
189+
and info.field_name == "partitioned_by_"
190+
):
186191
# this branch gets hit when we are deserializing from json because `partitioned_by` is stored as a List[str]
192+
# however, we should only invoke this if the list contains strings because this validator is also
193+
# called by Python models which might pass a List[exp.Expression]
187194
string_to_parse = (
188195
f"({','.join(v)})" # recreate the (a, b, c) part of "partitioned_by (a, b, c)"
189196
)
190-
parsed = parse_one(string_to_parse, into=exp.PartitionedByProperty)
197+
parsed = parse_one(
198+
string_to_parse, into=exp.PartitionedByProperty, dialect=get_dialect(info)
199+
)
191200
v = parsed.this.expressions if isinstance(parsed.this, exp.Schema) else v
192201

193202
expressions = list_of_fields_validator(v, info.data)

0 commit comments

Comments
 (0)