dbt-labs / dbt-codegen

Macros that generate dbt code
https://hub.getdbt.com/dbt-labs/codegen/latest/
Apache License 2.0
465 stars 103 forks source link

Unable to override database name #33

Closed niclas-roos closed 4 years ago

niclas-roos commented 4 years ago

Describe the bug

I'm trying to use generate_source in dbt cloud, running it in the prompt, to generate_source for my raw database in Snowflake, but it seems to be overridden by the default target database, analytics.

Steps to reproduce

I'm running the following script in the prompt: dbt run-operation generate_source --args '{schema_name: BINGADS, database_name: raw}'

I've installed packages using dbt deps

Expected results

version: 2

sources:
  - name: bingads
    database: raw
    tables:
      - name: account_history
      - name: account_impression_performance_daily_report
      - name: etc

Actual results

version: 2

sources:
  - name: bingads
    database: raw
    tables:

Screenshots and log output

Log output: On macro_generate_source: /* {"app": "dbt", "dbt_version": "0.18.0", "profile_name": "user", "target_name": "default", "connection_name": "macro_generate_source"} */

Part of log output showing the compiled SQL:

select distinct
    table_schema as "table_schema", table_name as "table_name"
from ANALYTICS.information_schema.tables
where table_schema ilike 'BINGADS'
and table_name ilike '%'
and table_name not ilike ''

System information

The contents of your packages.yml file:

packages:
  - package: fishtown-analytics/dbt_utils
    version: 0.6.1
  - package: fishtown-analytics/codegen
    version: 0.3.0

Which database are you using dbt with?

The output of dbt --version:

"dbt_version": "0.18.0"

The operating system you're using:

The output of python --version:

Additional context

Are you interested in contributing the fix?

clrcrl commented 4 years ago

:oof:, this is indeed a regression.

I checked it out, and it turns out the issue is in utils — fix is here

niclas-roos commented 4 years ago

Woohoo, my first bug!

Thanks for the fix! Should I close this?

clrcrl commented 4 years ago

When we merge that PR, this issue will magically close itself :)

Also — first bug? This was an incredibly useful report, I assumed you had done this plenty of times!