Skip to content

Commit a77b86a

Browse files
Fix condition is failing when parsing SqlAlchemy columns (#592)
* Fix issue * Update release notes * Add tests
1 parent 426395f commit a77b86a

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

DESCRIPTION.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Source code is also available at:
1010

1111
# Release Notes
1212
- v1.7.4(June 2, 2025)
13-
- Fix dependency on DESCRIBE TABLE columns quantity (differences in columns caused by Snowflake parameters)
13+
- Fix dependency on DESCRIBE TABLE columns quantity (differences in columns caused by Snowflake parameters).
14+
- Fix unnecessary condition was causing issues when parsing StructuredTypes columns.
1415
- Update README.md to include instructions on how to verify package signatures using cosign.
1516

1617
- v1.7.3(January 15, 2025)

src/snowflake/sqlalchemy/snowdialect.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,6 @@ def _get_schema_columns(self, connection, schema, **kw):
511511
)
512512
schema_name = self.denormalize_name(schema)
513513

514-
iceberg_table_names = self.get_table_names_with_prefix(
515-
connection,
516-
schema=schema_name,
517-
prefix=CustomTablePrefix.ICEBERG.name,
518-
info_cache=kw.get("info_cache", None),
519-
)
520-
521514
result = connection.execute(
522515
text(
523516
"""
@@ -578,10 +571,7 @@ def _get_schema_columns(self, connection, schema, **kw):
578571
col_type_kw["scale"] = numeric_scale
579572
elif issubclass(col_type, (sqltypes.String, sqltypes.BINARY)):
580573
col_type_kw["length"] = character_maximum_length
581-
elif (
582-
issubclass(col_type, StructuredType)
583-
and table_name in iceberg_table_names
584-
):
574+
elif issubclass(col_type, StructuredType):
585575
if (schema_name, table_name) not in full_columns_descriptions:
586576
full_columns_descriptions[(schema_name, table_name)] = (
587577
self.table_columns_as_dict(

tests/custom_tables/__snapshots__/test_reflect_snowflake_table.ambr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
}),
2222
])
2323
# ---
24+
# name: test_reflection_of_table_with_object_data_type
25+
'CREATE TABLE test_snowflake_table_reflection (\tid DECIMAL(38, 0) NOT NULL, \tname OBJECT, \tCONSTRAINT demo_name PRIMARY KEY (id))'
26+
# ---
2427
# name: test_simple_reflection_of_table_as_snowflake_table
2528
'CREATE TABLE test_snowflake_table_reflection (\tid DECIMAL(38, 0) NOT NULL, \tname VARCHAR(16777216), \tCONSTRAINT demo_name PRIMARY KEY (id))'
2629
# ---

tests/custom_tables/test_reflect_snowflake_table.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@
77
from snowflake.sqlalchemy import SnowflakeTable
88

99

10+
def test_reflection_of_table_with_object_data_type(
11+
engine_testaccount, db_parameters, sql_compiler, snapshot
12+
):
13+
metadata = MetaData()
14+
table_name = "test_snowflake_table_reflection"
15+
16+
create_table_sql = f"""
17+
CREATE TABLE {table_name} (id INT primary key, name OBJECT);
18+
"""
19+
20+
with engine_testaccount.connect() as connection:
21+
connection.exec_driver_sql(create_table_sql)
22+
23+
snowflake_test_table = Table(table_name, metadata, autoload_with=engine_testaccount)
24+
constraint = snowflake_test_table.constraints.pop()
25+
constraint.name = "demo_name"
26+
snowflake_test_table.constraints.add(constraint)
27+
28+
try:
29+
with engine_testaccount.connect():
30+
value = CreateTable(snowflake_test_table)
31+
32+
actual = sql_compiler(value)
33+
34+
assert actual == snapshot
35+
36+
finally:
37+
metadata.drop_all(engine_testaccount)
38+
39+
1040
def test_simple_reflection_of_table_as_sqlalchemy_table(
1141
engine_testaccount, db_parameters, sql_compiler, snapshot
1242
):

0 commit comments

Comments
 (0)