cross-posting from: [CT-1813] [CT-1378] [Bug] Python models not picking up custom schema · Issue #393 · dbt-labs/dbt-snowflake · GitHub
@patkearns10 and I managed to get to the bottom of this by live-debugging with a very helpful & generous user who was running into the issue!
I’m not sure why this bug is cropping up for some Snowflake users, and not others; I believe it should have been solved at the source in snowflake-connector-python==3.0 (included in dbt-snowflake>=1.4).
For anyone still experiencing the issue, this seems to be a valid workaround:
def model(dbt, session):
dbt.config(schema="custom_schema")
pandas_df = dbt.ref("my_model").to_pandas()
# add these lines
session.use_database(dbt.this.database)
session.use_schema(dbt.this.schema)
return pandas_df
We’ll see if there’s a way to include those session.use_* calls within the dbt materialization code, so that you don’t need to write it in every Python model that returns a Pandas dataframe.