dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.66k stars 1.6k forks source link

[Bug] Missing query-comments on insert statements for seeds #9647

Open OFlanagan opened 7 months ago

OFlanagan commented 7 months ago

Is this a new bug in dbt-core?

Current Behavior

Queries run against redshift do not all have the query-comment appended at the start. This query-comment is present for many CREATE and DELETE commands but is missing for inserts for seeds (the insert does not have query comments)

Expected Behavior

the documentation states "A string to inject as a comment in each query that dbt runs against your database" This means that the above inserts should also include the query-comment https://docs.getdbt.com/reference/project-configs/query-comment

Steps To Reproduce

define a seed in your dbt project ensure query-comments are enabled for your project run dbt run --select seed_name

Relevant log output

No response

Environment

- OS: Amazon Linux 23
- Python: 3.11.6
- dbt-core: 1.6.6

Which database adapter are you using with dbt?

redshift

Additional Context

Spun off of https://github.com/dbt-labs/dbt-core/issues/9617

OFlanagan commented 7 months ago

@dbeatty10 FYI

dbeatty10 commented 7 months ago

Suspected root cause

I suspect that the noop_statement called for the seed materialization here isn't including query comments for some reason.

However, regular statement does include the query comments via adapter.execute.

Reprex

Create this seed file:

seeds/my_seed.csv

id
1

Run these commands:

dbt clean
dbt seed --full-refresh

Open logs/dbt.log.

See that query comments are applied to the CTAS:

13:07:57.639380 [debug] [Thread-1 (]: On seed.my_project.my_seed: /* {"app": "dbt", "dbt_version": "1.7.8", "profile_name": "postgres", "target_name": "postgres", "node_id": "seed.my_project.my_seed"} */

    create table "postgres"."dbt_dbeatty"."my_seed" ("id" integer)

But see that they are missing for the insert statement:

[0m13:07:57.660162 [debug] [Thread-1 (]: On seed.my_project.my_seed: 
          insert into "postgres"."dbt_dbeatty"."my_seed" ("id") values
          (%s)
      ...