Open fordhoka opened 1 year ago
thanks for reaching out.
This might be an issue around looking for tables, I tried to reproduce and find that metadata.tables
(internally it's maintained by a dict) actually contains two tables, but the keys are one with schema name "schema.table_name1while the other doesn't have the schema
table_name2`.
but when foreign_key_constraints.pop().referred_table
is called, it's looking for the fully qualified schema.table_name2
which is not available in the
probably the code of getting foreign keys needs more logic: https://github.com/snowflakedb/snowflake-sqlalchemy/blob/main/src/snowflake/sqlalchemy/snowdialect.py#L400.
if you are interested and have time, could you take a look into that function?
hi and thank you for drawing our attention to this gap; we'll take a look
Please answer these questions before submitting your issue. Thanks!
3.10.10
macOS-13.4-x86_64-i386-64bit
pip freeze
)?Relevant modules:
test_schema
, and tablestest_table_1
andtest_table_2
.test_table_1
contains a foreign key referencingtest_table_2
I expected:
metadata.tables
to contain 2 keys,test_schema.test_table_1
andtest_schema.test_table_2
,Table
objects to be associated withtest_schema
, andmetadata.tables['test_schema.test_table_1'].foreign_key_constraints.pop().referred_table
should resolve to theTable
object fortest_schema.test_table_2
.Instead, it contained
test_schema.test_table_1
andtest_table_2
. TheTable
object returned fortest_table_2
was not associated with a schema.metadata.tables['test_schema.test_table_1'].foreign_key_constraints.pop().referred_table
raises the following error:I have a workaround for this issue: list all of the foreign keys using
SHOW IMPORTED KEYS
, pull out all of the fk-referenced table names, and include them explicitly along with the requested tables inonly=
; and then filter the non-schema-qualified tables out ofmetadata.tables
. This is unwieldy, and made even more so by https://github.com/snowflakedb/snowflake-sqlalchemy/issues/388.snowflake_sqlalchemy_logs.txt