Snowflake-Labs / schemachange

A Database Change Management tool for Snowflake
Apache License 2.0
517 stars 228 forks source link

Default Warehouse Not Selected #235

Open allstream opened 8 months ago

allstream commented 8 months ago

Based on the versions of schemachange I've installed be it 3.6.1, 3.6.0 and 3.5.4 I've received an error when just starting a project: SQL query: SELECT CREATED, LAST_ALTERED FROM METADATA.INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = REPLACE('SCHEMACHANGE','"','') AND TABLE_NAME = replace('CHANGE_HISTORY','"','') Traceback (most recent call last): File "/Users/username/PycharmProjects/snowflake-platform/venv/bin/schemachange", line 8, in <module> sys.exit(main()) ^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/schemachange/cli.py", line 888, in main deploy_command(config) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/schemachange/cli.py", line 502, in deploy_command change_history_metadata = session.fetch_change_history_metadata(change_history_table) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/schemachange/cli.py", line 370, in fetch_change_history_metadata results = self.execute_snowflake_query(query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/schemachange/cli.py", line 365, in execute_snowflake_query raise e File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/schemachange/cli.py", line 358, in execute_snowflake_query res = self.con.execute_string(query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/connection.py", line 833, in execute_string ret = list(stream_generator) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/connection.py", line 851, in execute_stream cur.execute(sql, _is_put_get=is_put_or_get, **kwargs) File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/cursor.py", line 1136, in execute Error.errorhandler_wrapper(self.connection, self, error_class, errvalue) File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/errors.py", line 290, in errorhandler_wrapper handed_over = Error.hand_to_other_handler( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/errors.py", line 345, in hand_to_other_handler cursor.errorhandler(connection, cursor, error_class, error_value) File "/Users/username/PycharmProjects/snowflake-platform/venv/lib/python3.12/site-packages/snowflake/connector/errors.py", line 221, in default_errorhandler raise error_class( snowflake.connector.errors.ProgrammingError: 000606 (57P03): No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.

To Reproduce Steps to reproduce the behavior:

  1. Install schema change pip install schemachange
  2. Configure the project
  3. Run the command schemachange --config-folder=/Users/usename/.snowflake/ --create-change-history-table -w initial_warehouse
  4. See error: snowflake.connector.errors.ProgrammingError: 000606 (57P03): No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.

Expected behavior This should lead to the default change history table to be created and without error.

This is cringe for getting started for new users

dataalias commented 8 months ago

This is the same issue as: https://github.com/Snowflake-Labs/schemachange/issues/224 https://github.com/Snowflake-Labs/schemachange/issues/233

allstream commented 8 months ago

After a number of wild guesses with the command line parameters, I was able to get things working by surrounding the warehouse parameter in escaped quotes, see below:

schemachange --config-folder=/Users/usename/.snowflake/ --snowflake-warehouse=\"initial_warehouse\" --create-change-history-table

Pretty cringe, but it worked for me