Skip to content

Commit 0eec727

Browse files
sfc-gh-stakedasfc-gh-abhatnagar
authored andcommitted
SNOW-127998 SQLAlchemy empty comments
1 parent ca9dfb7 commit 0eec727

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

snowdialect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def _get_table_columns(self, connection, table_name, schema=None, **kw):
461461
'nullable': is_nullable == 'YES',
462462
'default': column_default,
463463
'autoincrement': is_identity == 'YES',
464-
'comment': comment,
464+
'comment': comment if comment != '' else None,
465465
'primary_key': (column_name in schema_primary_keys[table_name][
466466
'constrained_columns']) if current_table_pks else False,
467467
})
@@ -583,7 +583,7 @@ def get_table_comment(self, connection, table_name, schema=None, **kw):
583583
)
584584
cursor = connection.execute(sql_command)
585585
ans = cursor.fetchone()
586-
return {'text': ans['comment']}
586+
return {'text': ans['comment'] if ans['comment'] else None}
587587

588588

589589
@sa_vnt.listens_for(Table, 'before_create')

test/test_core.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,3 +1206,17 @@ def mock_helper(command, *args, **kwargs):
12061206
assert len(column_metadata) == 4
12071207
# Clean up
12081208
metadata.drop_all(engine_testaccount)
1209+
1210+
1211+
def test_empty_comments(engine_testaccount):
1212+
"""Test that no comment returns None"""
1213+
table_name = ''.join(random.choice(string.ascii_uppercase) for _ in range(5))
1214+
try:
1215+
engine_testaccount.execute("create table public.{} (\"col1\" text);".format(table_name))
1216+
engine_testaccount.execute("select comment from information_schema.columns where table_name='{}'".format(table_name)).fetchall()
1217+
inspector = inspect(engine_testaccount)
1218+
columns = inspector.get_columns(table_name, schema='PUBLIC')
1219+
assert inspector.get_table_comment(table_name, schema='PUBLIC') == {'text': None}
1220+
assert all([c['comment'] is None for c in columns])
1221+
finally:
1222+
engine_testaccount.execute("drop table public.{}".format(table_name))

0 commit comments

Comments
 (0)