Skip to content

SNOW-2852779: Reflecting metadata fails when schema is None in Snowflake SQLAlchemy #623

@Dejwwik

Description

@Dejwwik

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Python 3.13.0 (main, Oct 16 2024, 08:05:40) [Clang 18.1.8 ]

  1. What operating system and processor architecture are you using?

macOS-15.6.1-arm64-arm-64bit-Mach-O

  1. What are the component versions in the environment (pip freeze)?
sqlalchemy==2.0.43
snowflake-connector-python==4.0.0
snowflake-sqlalchemy==1.7.7
  1. What did you do?
metadata = MetaData()
metadata.reflect(bind=engine, views=True)

for table in metadata.sorted_tables:
    print(str(CreateTable(table).compile(engine)))

  1. What did you expect to see?

I tried to list all the tables in a schema, but the dialect’s default schema is None, and no schema was provided in the reflect() call. I assumed the default schema would be applied automatically—or that no schema would be used at all. Instead, schema ends up being None, and the process fails when normalizing the schema name.

dejwwik@lukas_mac ~/Desktop/Work/Backend (snowflake_connector) % uv run tmp/test_snoflake.py                                   
Traceback (most recent call last):
  File "/Users/dejwwik/Desktop/Work/Backend/tmp/test_snoflake.py", line 112, in <module>
    metadata.reflect(bind=engine, views=True)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/sqlalchemy/sql/schema.py", line 5836, in reflect
    insp.get_table_names(schema)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/sqlalchemy/engine/reflection.py", line 406, in get_table_names
    return self.dialect.get_table_names(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        conn, schema, info_cache=self.info_cache, **kw
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/snowflake/sqlalchemy/snowdialect.py", line 662, in get_table_names
    ret = self._get_schema_tables_info(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        connection, schema, info_cache=kw.get("info_cache", None)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ).keys()
    ^
  File "<string>", line 2, in _get_schema_tables_info
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/sqlalchemy/engine/reflection.py", line 106, in cache
    ret = fn(self, con, *args, **kw)
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/snowflake/sqlalchemy/snowdialect.py", line 645, in _get_schema_tables_info
    f"SHOW /* sqlalchemy:get_schema_tables_info */ TABLES IN SCHEMA {self._denormalize_quote_join(schema)}"
                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/dejwwik/Desktop/Work/Backend/.venv/lib/python3.13/site-packages/snowflake/sqlalchemy/snowdialect.py", line 293, in _denormalize_quote_join
    split_idents = reduce(
        operator.add,
        [ip._split_schema_by_dot(ids) for ids in idents if ids is not None],
    )
TypeError: reduce() of empty iterable with no initial value

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions