You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A highly specific edge case for code that worked in v1.0, but not in v1.1.
Reproduction case
-- macros/test_get_cols.sql
{% test get_cols_in(model) %}
{# The step which causes the issue #}
{%-set relation =api.Relation.create(schema=model.schema, identifier=model.table) if execute -%}
{% set columns =adapter.get_columns_in_relation(relation) %}
select
{% for col in columns %}
{{ col.name }} {{ "," if not loop.last }}
{% endfor %}
from {{ model }}
limit0
{% endtest %}
Starting in v1.1, these use a new mechanism (DatasetReference + TableReference), which expect all of database/project, schema/dataset, and table_name to be present.
Previously, we were using a legacy / deprecated conn.handle.dataset endpoint instead. We passed the whole connection into that endpoint, so if the project was missing, we'd use the default project from the connection in its place:
I definitely don't want to go back to the legacy endpoint! I think it should be quite simple for us to restore the previous behavior. In the case where database is None, let's fill in with the configured database (from credentials or GCloud default).
defget_bq_table(self, database, schema, identifier):
"""Get a bigquery table for a schema/model."""conn=self.get_thread_connection()
# backwards compatibility: fill in with defaults if not specifieddatabase=databaseorconn.credentials.databaseschema=schemaorconn.credentials.schematable_ref=self.table_ref(database, schema, identifier)
returnconn.handle.get_table(table_ref)
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
get_columns_in_relation when database is missing
[CT-604] get_columns_in_relation when database is missing
May 4, 2022
Slack thread
A highly specific edge case for code that worked in v1.0, but not in v1.1.
Reproduction case
When I run this code locally, I see this error in the debug logs (
logs/dbt.log
):Indeed, it looks like this error is because the
project
/database
is empty whenrelation
is created. When I update that line of code to be:It works just fine.
So the question is, how was this working previously?
Root cause
The origin of this change: #98
get_columns_in_relation
callsget_bq_table
:dbt-bigquery/dbt/adapters/bigquery/connections.py
Lines 550 to 559 in 8679a8b
Starting in v1.1, these use a new mechanism (
DatasetReference
+TableReference
), which expect all ofdatabase
/project
,schema
/dataset
, andtable_name
to be present.Previously, we were using a legacy / deprecated
conn.handle.dataset
endpoint instead. We passed the whole connection into that endpoint, so if theproject
was missing, we'd use the defaultproject
from the connection in its place:dbt-bigquery/dbt/adapters/bigquery/connections.py
Lines 490 to 507 in c45c8b0
Resolution
I definitely don't want to go back to the legacy endpoint! I think it should be quite simple for us to restore the previous behavior. In the case where
database
isNone
, let's fill in with the configureddatabase
(from credentials or GCloud default).The text was updated successfully, but these errors were encountered: