Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2737] [Bug] A misleading error message when contracts enabled but not implemented yet #7943

Closed
2 tasks done
Tracked by #7372
miloszbednarzak opened this issue Jun 21, 2023 · 3 comments · Fixed by #8024
Closed
2 tasks done
Tracked by #7372
Assignees
Labels
bug Something isn't working model_contracts
Milestone

Comments

@miloszbednarzak
Copy link

miloszbednarzak commented Jun 21, 2023

Is this a new bug in dbt-bigquery?

  • I believe this is a new bug in dbt-bigquery
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

[edit] see #7943

When dbt run -s [model] the query run in BigQuery is cut out resulting with an SyntaxError.

When examine GBQ run history, it's clear that the query that should be run is entirely cut out. dbt logs shows the same.

Expected Behavior

Query should be equivalent with the compiled model.

Steps To Reproduce

model name: test.sql
with file content:

select 1

run dbt run -s test

Relevant log output

15:09:21  On model.hermod.fct__user_quiz_results: 
    select * from (
        select 1
    ) as __dbt_sbq
    where false
    limit 0
15:09:21  On model.hermod.fct__user_quiz_results: 
    select * from (
        select
    
    ) as __dbt_sbq
    where false
    limit 0
15:09:21  BigQuery adapter: Retry attempt 1 of 3 after error: BadRequest('Syntax error: Unexpected ")" at [5:5]')
...

Environment

- OS:
- Python:
- dbt-core: 1.5.1
- dbt-bigquery: 1.5.2

Additional Context

this behaviour is present both in dbt cloud and when run locally.

@miloszbednarzak miloszbednarzak added bug Something isn't working triage labels Jun 21, 2023
@github-actions github-actions bot changed the title [Bug] Compiled query is cut out from the run in the GBQ job [ADAP-640] [Bug] Compiled query is cut out from the run in the GBQ job Jun 21, 2023
@miloszbednarzak
Copy link
Author

Okay, I found the problem. Occurs when contracts are enabled but there is no entry in schema.yml yet.

So the real issue becomes a misleading error message instead. dbt should warn that the contract for the model is not implemented instead of throwing a SyntaxError

@miloszbednarzak miloszbednarzak changed the title [ADAP-640] [Bug] Compiled query is cut out from the run in the GBQ job [ADAP-640] [Bug] A misleading error message when contracts enabled but not implemented yet Jun 22, 2023
@dbeatty10 dbeatty10 transferred this issue from dbt-labs/dbt-bigquery Jun 24, 2023
@github-actions github-actions bot changed the title [ADAP-640] [Bug] A misleading error message when contracts enabled but not implemented yet [CT-2737] [ADAP-640] [Bug] A misleading error message when contracts enabled but not implemented yet Jun 24, 2023
@jtcohen6 jtcohen6 self-assigned this Jun 25, 2023
@dbeatty10
Copy link
Contributor

Thanks for reporting this @miloszbednarzak !

@jtcohen6 may provide additional commentary, but in the meantime, here are two different ways to reproduce what you reported:

Reprex 1

dbt_project.yml

name: "my_project"
version: "1.0.0"
config-version: 2
profile: "sandcastle"

models/my_model.sql

{{ config(contract={"enforced": true})}}

select 1 as id

Run the model:

dbt run -s my_model

Reprex 2

dbt_project.yml

name: "my_project"
version: "1.0.0"
config-version: 2
profile: "sandcastle"

models:
  my_project:
    +contract:
      enforced: true

models/my_model.sql

select 1 as id

Run the model:

dbt run -s my_model

@dbeatty10 dbeatty10 removed the triage label Jun 27, 2023
@jtcohen6 jtcohen6 changed the title [CT-2737] [ADAP-640] [Bug] A misleading error message when contracts enabled but not implemented yet [CT-2737] [Bug] A misleading error message when contracts enabled but not implemented yet Jul 4, 2023
@jtcohen6
Copy link
Contributor

jtcohen6 commented Jul 4, 2023

Thanks @dbeatty10!

Agree we should raise a nicer error message here. We just need to add a check to ensure that model["columns"] exists and is not empty, before trying to template it into a query:

{#--Obtain the column schema provided by the schema file by generating an 'empty schema' query from the model's columns. #}
{%- set schema_file_provided_columns = get_column_schema_from_query(get_empty_schema_sql(model['columns'])) -%}

Took it for a quick spin:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working model_contracts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants