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

[ADAP-939] [Bug] cannot reference permanent table from temporary table constraint when running incremental model with a foreign key #628

Open
2 tasks done
aranke opened this issue Oct 10, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@aranke
Copy link
Member

aranke commented Oct 10, 2023

Most of the content below is copy-pasted from @amardatar within dbt-labs/dbt-core#8022

Is this a new bug in dbt-redshift?

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

Current Behavior

When running an incremental model with contract enforced and a foreign key, the model will fail on subsequent updates.

Expected Behavior

The update should succeed without an error.

Steps To Reproduce

First run a statement like:

create table if not exists numbers (n int not null primary key)

Then, given a schema.yml file:

version: 2

models:
  - name: test
    config:
      contract:
        enforced: true
      materialized: incremental
      on_schema_change: append_new_columns
      unique_key: n
    columns:
      - name: n
        data_type: integer
        constraints:
          - type: foreign_key
            expression: "numbers (n)"

And a SQL file:

select 1 as n

dbt will succeed on the first run, and subsequently fail with the error:

cannot reference permanent table from temporary table constraint

As per the error returned, the issue appears to be that while rendering a temporary table as part of the update, dbt will also render the foreign key constraint (which is not valid in the context of a temporary table). This leads to the above failure.

Relevant log output

No response

Environment

- OS: macOS Ventura 13.4.1
- Python: 3.11.4
- dbt: 1.5.2
@aranke aranke added bug Something isn't working triage labels Oct 10, 2023
@github-actions github-actions bot changed the title [Bug] cannot reference permanent table from temporary table constraint when running incremental model with a foreign key [ADAP-939] [Bug] cannot reference permanent table from temporary table constraint when running incremental model with a foreign key Oct 10, 2023
@dbeatty10
Copy link
Contributor

@aranke verified a fix for Postgres in dbt-labs/dbt-core#8768 and then created this backlog ticket for Redshift.

@dbeatty10 dbeatty10 removed the triage label Oct 10, 2023
@jtcohen6
Copy link
Contributor

I think the fix for dbt-postgres was too large in scope, leading to other issues:

@emmyoop
Copy link
Member

emmyoop commented Oct 25, 2023

The original fix (dbt-labs/dbt-core#8022) was modified slightly in dbt-labs/dbt-core#8889 to still enforce the contract.

@mikealfare mikealfare added the refinement Product or leadership input needed label Jan 17, 2024
@nathaniel-may nathaniel-may added support_rotation and removed refinement Product or leadership input needed labels Feb 7, 2024
@bdgeise
Copy link

bdgeise commented Oct 11, 2024

Ran into this issue today and created a PR to address #927

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

7 participants