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

[Bug] Can't use data contract constraints together with 'time_ingestion_partitioning="true"' in incremental models #1430

Open
2 tasks done
LennartKloppenburg opened this issue Dec 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@LennartKloppenburg
Copy link

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

Dbt errors when combining an incremental model with time_ingestion_partitioning enabled and also enforcing model contract constraints.

I'd love to know whether this is intended or if this is potentially a bug that could be worked on :)

Expected Behavior

Dbt should not error out on columns 'consumed' by the time_ingestion_partitioning flags that are in the dbt model but not factually in the output schema or BigQuery table when enforcing model contract constraints.

The partitioning column should not have 'presence enforcement' when this flag is enabled (ideally).

Steps To Reproduce

# incremental_test.sql
{{ config(
    materialized="incremental",
    on_schema_change="fail",
    partition_by={
      "field": "created_date",
      "data_type": "timestamp",
      "granularity": "day",
      "time_ingestion_partitioning": true,
    }
) }}

SELECT
  'A' AS letter,
  1 AS digit,
  CURRENT_DATE() AS created_date

When enforcing the data contract like so:

# incremental_test.yaml
models:
  - name: incremental_test
    config:
      contract:
        enforced: true
    columns:
      - name: letter
        data_type: STRING
        constraints:
          - type: not_null
      - name: digit
        data_type: INTEGER
        constraints:
          - type: not_null

and subsequently building with dbt build --select incremental_test I get the error attached in the log output.

Relevant log output

This model has an enforced contract that failed.
  Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.
  
  | column_name  | definition_type | contract_type | mismatch_reason     |
  | ------------ | --------------- | ------------- | ------------------- |
  | created_date | DATE            |               | missing in contract |


### Environment

```markdown
- OS: dbt-cloud (through dbt Cloud CLI 0.38.18)
- Python: 3.12
- dbt-core: 1.9 (latest)
- dbt-bigquery: 1.9.0

Additional Context

No response

@LennartKloppenburg LennartKloppenburg added bug Something isn't working triage labels Dec 11, 2024
@amychen1776
Copy link

Hello @LennartKloppenburg ! It looks like you have found a specific bug. Quoting Jeremey

This BQ issue is a pretty specific case, at the intersection of
model contracts
the (BQ-only) time_ingestion_partitioning config

In the example the user provides, technically the created_date column is returned by the model's query, but it's not included in the actual table produced by the model, because it's used as the pseudo-column for ingestion-time partitioning.

We think a workaround is if you added created_date to your yaml contract. Could you try that and let us know if it works?

@LennartKloppenburg
Copy link
Author

Hi @amychen1776 sorry, your reply was lost during the Christmas holidays :) Thanks a lot for getting back to me! I will give this a go and let you know :) I remember trying something like this but encountering a different error, but let me verify that for you.

@amychen1776
Copy link

Thank you :) and no worries! I'm glad you had some rest away from tech lol

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

No branches or pull requests

2 participants