Snowflake-Labs / schemachange

A Database Change Management tool for Snowflake
Apache License 2.0
482 stars 219 forks source link

Strange ValueError issues in 3.5.0 #149

Closed natethegreat44 closed 1 year ago

natethegreat44 commented 1 year ago

Hi, We recently (and accidentally) upgraded to version 3.5.0 yesterday and started receiving some really strange errors when running schemachange.

#0 0.073 Running Snowflake migration script on 'dev' environment                                                        
#0 5.357 schemachange version: 3.5.0                                                                                    
#0 5.357 Using config file: configs/dev/schemachange-config.yml                                                         
#0 5.357 Using root folder /src/snowflake-schema-change/sql                                                             
#0 5.357 Using variables:
#0 5.357   ACQ_SCHEMA: ACQ
#0 5.357   S3_BUCKET: our-s3-bucket
#0 5.357   AWS_SNS_TOPIC: arn:aws:sns:us-east-1:**REDACTED**
#0 5.357   integration:
#0 5.357     NAME: ACQ_PPL_INTEGRATION_DEV
#0 5.357     AWS_SNS_TOPIC_ARN: arn:aws:sns:us-east-1:**REDACTED**
#0 5.357     AWS_SNS_ROLE_ARN: arn:aws:iam::**REDACTED**
#0 5.357   secrets:
#0 5.357     AWS_KEY_ID: ********************
#0 5.357     AWS_SECRET_KEY: ****************************************
#0 5.357 
#0 5.357 Using Snowflake account **REDACTED**
#0 5.357 Using default role DEV_FULL_CONTROL
#0 5.357 Using default warehouse DEV_WH
#0 5.357 Using default database DEV_DB
#0 5.357 Traceback (most recent call last):
#0 5.357   File "/usr/local/bin/schemachange", line 8, in <module>
#0 5.357     sys.exit(main())
#0 5.357   File "/usr/local/lib/python3.9/dist-packages/schemachange/cli.py", line 865, in main
#0 5.357     deploy_command(config) 
#0 5.357   File "/usr/local/lib/python3.9/dist-packages/schemachange/cli.py", line 488, in deploy_command
#0 5.357     raise ValueError(_err_ch_missing.format(change_history_metadata))
#0 5.357 KeyError: 'database_name'

The config file we're using is attached (had to rename to .txt so that github would accept it - it's just .yml in our folder). schemachange-config.yml.txt

Somehow it seems that the config isn't being loaded quite correctly. But it's strange - things seem to mostly work in other places. We traced through the code and don't believe it should have ever gotten to line 488 because the table doesn't yet exist and we specify create-change-history-table: true in the config file, but it's false by the time we hit line 482. The resulting KeyError is a further indication of the weirdness and seems to actually be the .format call not liking that a dictionary was passed in for parameters. The change_history_metadata object looks fine if we print it out.

The exact same setup works fine with schemachange 3.4.2. We're using Python 3.9.

We're at a loss as to what's actually happening here. Could you please help us? Would be glad to provide any other details if I've missed them.

Thank you very much!

sfc-gh-jhansen commented 1 year ago

Thanks for pointing this out @natethegreat44, and I found the bug. Just published 3.5.1 with the fix.

We did some major refactoring in 3.5.0 and missed this.

natethegreat44 commented 1 year ago

Awesome @sfc-gh-jhansen! Thank you very much!