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-3487] [Bug] dbt show --inline does not work when all models are disabled in dbt_project.yml #9269

Closed
2 tasks done
pgoslatara opened this issue Dec 12, 2023 · 8 comments · Fixed by #10264
Closed
2 tasks done
Assignees
Labels

Comments

@pgoslatara
Copy link
Contributor

Is this a new bug in dbt-core?

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

Current Behavior

When I run dbt show --inline it works. When I add a --target flag it does not work.

Expected Behavior

dbt show works when a target is supplied.

Steps To Reproduce

I'm running the latest version of dbt-biguery with this profiles.yml:

dbt_docs:
    target: dev
    outputs:
        dev:
            type: bigquery
            method: oauth
            project: <PROJECT_ID>
            schema: <ENV_VAR>
            location: europe-west4
            threads: 4
        dev2:
            type: bigquery
            method: oauth
            project: <PROJECT_ID>
            schema: <ENV_VAR>
            location: europe-west4
            threads: 4

Note that dev2 is an exact copy of dev.

Run the following commands and observe differing behaviour:

$ dbt show --inline "SELECT 1 AS id"
$ dbt show --inline "SELECT 1 AS id" --target dev
$ dbt show --inline "SELECT 1 AS id" --target dev2

The first 2 commands return a result, the third command does not.

Relevant log output

$ dbt show --inline "SELECT 1 AS id"
15:13:44  Running with dbt=1.7.3
15:13:44  Registered adapter: bigquery=1.7.2
15:13:44  Unable to do partial parsing because of a version mismatch
15:13:46  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- tests
15:13:47  Found 1 model, 1 seed, 0 sources, 0 exposures, 0 metrics, 949 macros, 0 groups, 0 semantic models
15:13:47  
15:13:48  Concurrency: 4 threads (target='dev')
15:13:48  
15:13:49  Previewing inline node:
| id |
| -- |
|  1 |

$ dbt show --inline "SELECT 1 AS id" --target dev
15:13:54  Running with dbt=1.7.3
15:13:55  Registered adapter: bigquery=1.7.2
15:13:55  Unable to do partial parsing because config vars, config profile, or config target have changed
15:13:57  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- tests
15:13:57  Found 1 model, 1 seed, 0 sources, 0 exposures, 0 metrics, 949 macros, 0 groups, 0 semantic models
15:13:57  
15:13:58  Concurrency: 4 threads (target='dev')
15:13:58  
15:13:59  Previewing inline node:
| id |
| -- |
|  1 |

$ dbt show --inline "SELECT 1 AS id" --target dev2
15:14:03  Running with dbt=1.7.3
15:14:03  Registered adapter: bigquery=1.7.2
15:14:03  Unable to do partial parsing because config vars, config profile, or config target have changed
15:14:06  Found 1 seed, 0 sources, 0 exposures, 0 metrics, 949 macros, 0 groups, 0 semantic models
15:14:06  
15:14:06  Nothing to do. Try checking your model configs and model specification args

Environment

- OS:Ubuntu 22.04
- Python: Python 3.10.12
- dbt:

Core:
  - installed: 1.7.3
  - latest:    1.7.3 - Up to date!

Plugins:
  - bigquery: 1.7.2 - Up to date!

Which database adapter are you using with dbt?

bigquery

Additional Context

No response

@pgoslatara pgoslatara added bug Something isn't working triage labels Dec 12, 2023
@github-actions github-actions bot changed the title [Bug] dbt show --inline does not work when non-default target is specified [CT-3487] [Bug] dbt show --inline does not work when non-default target is specified Dec 12, 2023
@dbeatty10 dbeatty10 self-assigned this Dec 12, 2023
@dbeatty10
Copy link
Contributor

dbeatty10 commented Dec 13, 2023

@pgoslatara Do you know what is different between your dbt project when you use different targets?

It looks like you are able to successfully use dbt show --inline when --target dev, but not able to when --target dev2.

This makes me think it might have something to do with target-specific logic you have within your project.

The only thing that I can see that is different in your example output is that the first two have this warning (but the last one doesn't):

15:13:57  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- tests

I tried to reproduce the same issue you are seeing, but I wasn't able. See below for the files and commands that I used.

Could you try tweaking these example files to see the same unexpected behavior that you described?

Files

These are the only two files I put in my project (no models or anything else):

dbt_project.yml

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

clean-targets:
  - dbt_packages
  - '{{ env_var("DBT_TARGET_PATH", "target") }}'
  - '{{ env_var("DBT_LOG_PATH", "logs") }}'

profiles.yml

bigquery:
  target: blue

  outputs:
    dev:
      method: service-account
      keyfile: '{{ env_var(''BIGQUERY_SERVICE_KEY_PATH'') }}'
      project: '{{ env_var(''BIGQUERY_TEST_DATABASE'') }}'
      schema: dbt_dbeatty
      threads: 10
      type: bigquery

    dev2:
      method: service-account
      keyfile: '{{ env_var(''BIGQUERY_SERVICE_KEY_PATH'') }}'
      project: '{{ env_var(''BIGQUERY_TEST_DATABASE'') }}'
      schema: dbt_dbeatty
      threads: 10
      type: bigquery

Commands

dbt show --inline "SELECT 1 AS id" --target dev
dbt show --inline "SELECT 1 AS id" --target dev2

Output

(env) $ dbt show --inline "SELECT 1 AS id" --target dev
22:45:27  Running with dbt=1.7.3
22:45:28  Registered adapter: bigquery=1.7.2
22:45:28  Found 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
22:45:28  
22:45:28  Concurrency: 10 threads (target='dev')
22:45:28  
22:45:29  Previewing inline node:
| id |
| -- |
|  1 |

(env) $ dbt show --inline "SELECT 1 AS id" --target dev2
22:45:34  Running with dbt=1.7.3
22:45:35  Registered adapter: bigquery=1.7.2
22:45:35  Unable to do partial parsing because config vars, config profile, or config target have changed
22:45:36  Found 0 sources, 0 exposures, 0 metrics, 447 macros, 0 groups, 0 semantic models
22:45:36  
22:45:36  Concurrency: 10 threads (target='dev2')
22:45:36  
22:45:37  Previewing inline node:
| id |
| -- |
|  1 |

@pgoslatara
Copy link
Contributor Author

@dbeatty10 Thanks for looking into this. Good idea on the project configuration, I figured out what's causing this issue. We have some jinja logic that disables our models when any target other than "dev" is used (I know, it's complex 😃). Essentially what's happening is that when models are disabled then dbt show does not return anything, as evidenced by the commands in the issue description.

To reproduce, add this to your dbt_project.yml:

models:
  +enabled: false

Regardless of what target you select, running dbt show --inline "SELECT 1 AS id" will not return a value.

@dbeatty10 dbeatty10 changed the title [CT-3487] [Bug] dbt show --inline does not work when non-default target is specified [CT-3487] [Bug] dbt show --inline does not work when all models are disabled in dbt_project.yml Dec 13, 2023
@dbeatty10
Copy link
Contributor

Reprex

Depending on the content of dbt_project.yml, this command either shows results (as expected) or doesn't:

dbt show --inline "select 1 as id"

This works:

models/my_model.sql

{{ config(enabled=false) }}

select 1 as id

But this doesn't:

dbt_project.yml

models:
  +enabled: false

@dbeatty10 dbeatty10 removed the triage label Dec 13, 2023
@dbeatty10 dbeatty10 removed their assignment Dec 13, 2023
@pgoslatara
Copy link
Contributor Author

I've traced this issue to this line:

for uid in self.job_queue.get_selected_nodes():

self.job_queue.get_selected_nodes() returns zero nodes when models are disabled. What approach to take to fix this I do not know, this feels rather nested in terms of impact.

@dbeatty10
Copy link
Contributor

Acceptance criteria

dbt core should disregard selection / selectors altogether when running in inline mode during "interactive compile" and dbt show.

i.e., whenever the --inline flag is passed to dbt compile or dbt show, dbt should render that Jinja regardless if:

  • the dbt project has 0 nodes or many
  • all nodes are disabled or not
  • a --select or --selector flag is passed that selects 0 nodes
  • the default selector selects 0 nodes
  • etc.

In the case of dbt show, it should also run it as a SQL query and return the result set.

@dbeatty10
Copy link
Contributor

We've identified a handful of edge cases where --inline doesn't work as desired.

Case 1

See #9269 (comment)

Case 2

dbt compile --select something_that_doesnt_match_any_nodes --inline "select 1 as id"
dbt show --select something_that_doesnt_match_any_nodes --inline "select 1 as id"

Case 3

selectors.yml

selectors:
  - name: no_nodes_for_you
    description: Something that matches no nodes
    default: false
    definition:
      union:
        - method: fqn
          value: "*"
        - exclude:
          - method: fqn
            value: "*"
dbt compile --selector no_nodes_for_you --inline "select 1 as id"
dbt show --selector no_nodes_for_you --inline "select 1 as id"

Case 4

Same selectors.yml as Case 3, except make it the default instead:

    default: true
dbt compile --inline "select 1 as id"
dbt show --inline "select 1 as id"

@gshank
Copy link
Contributor

gshank commented Jun 4, 2024

This is a duplicate of #8943, so I've reassigned it to me.

@gshank
Copy link
Contributor

gshank commented Jun 4, 2024

@graciegoheen When all models are disabled via dbt_project.yml, that includes the inline model node that's created with "--inline". So it's not clear that that is actually a bug, although it is somewhat unexpected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants