Snowflake-Labs / schemachange

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

Role, Database, and Warehouse Not Resetting Before Logging #161

Closed nwea-yeti-jw closed 10 months ago

nwea-yeti-jw commented 1 year ago

We found that after running a migration, the Snowflake role, database, and warehouse are not resetting if those values changed within the migration. In other words, if the migration itself contains use role my_role; within the migration, the insert query for the log will still try to use that role rather than what was set in environment variables. This created an issue when we found that the role may not necessarily have privileges on the database where the logs are inserted.

In the current cli.py script on line 433, you can see that self.reset_session() is called, but it is not called again after executing the migration; therefore when line 450 that has the log execution is called, the query will use the last role, database, and warehouse if set within the migration. We have confirmed this in testing.

The workaround we have implemented is reverting to pre-3.5.0 and this is successful. We have also submitted a small PR with a fix.

sfc-gh-jhansen commented 10 months ago

These changes were deployed in v3.6.0, see PR #195