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-540] [Bug] 'target' suddenly not available at compile time in selectors.yml #5131

Closed
1 task done
ljhopkins2 opened this issue Apr 21, 2022 · 6 comments · Fixed by #5136
Closed
1 task done

[CT-540] [Bug] 'target' suddenly not available at compile time in selectors.yml #5131

ljhopkins2 opened this issue Apr 21, 2022 · 6 comments · Fixed by #5136
Assignees
Labels
bug Something isn't working regression
Milestone

Comments

@ljhopkins2
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

After upgrading to dbt v1.0.5, I get the following error when compiling my model:

Compilation Error
  Could not render {{ target.name == 'dev' | as_bool }}: 'target' is undefined

Expected Behavior

The project should compile without error, as it did in earlier post-v1 releases.

Steps To Reproduce

  1. Add a selector like this to selectors.yml
selectors:
  - name: dev_defer_snapshots
    default: "{{ target.name == 'dev' | as_bool }}"
    definition:
      method: fqn
      value: '*'
      exclude:
        - method: config.materialized
          value: snapshot
  1. Compile the project with dbt v1.0.5
  2. Note the error
  3. Comment out the line containing default: "{{ target.name == 'dev' | as_bool }}"
  4. Compile the project
  5. Note no error

Relevant log output

No response

Environment

- OS: MacOS 12.3.1
- Python: 3.9.10
- dbt: 1.0.5

What database are you using dbt with?

redshift

Additional Context

No response

@ljhopkins2 ljhopkins2 added bug Something isn't working triage labels Apr 21, 2022
@github-actions github-actions bot changed the title [Bug] 'target' suddenly not available at compile time in selectors.yml [CT-540] [Bug] 'target' suddenly not available at compile time in selectors.yml Apr 21, 2022
@jtcohen6
Copy link
Contributor

jtcohen6 commented Apr 21, 2022

@ljhopkins2 Thanks for the report! We'll get on this.

Could it be an unintended side-effect of #4878?

The target-based default use case is an increasingly common one, and it's documented here: https://docs.getdbt.com/reference/node-selection/yaml-selectors/#default

In addition to the fix here, we need a test case for it.

@jtcohen6
Copy link
Contributor

jtcohen6 commented Apr 21, 2022

Confirmed that change looks to be the cause. We need our renderers / rendering contexts to be such that:

  • packages.yml supports secret env vars, but not target (which isn't set during deps)
  • selectors.yml supports target, but not secret env vars

@ljhopkins2 In the meantime, could you work around this by using an env_var instead of target.name?

@ljhopkins2
Copy link
Contributor Author

@jtcohen6 Thanks for suggesting a workaround. I'll probably just leave it commented out for now, though: short-term I can just remember to --exclude in the dev env; the bigger impact for me was that it was causing cloud jobs to fail, and that was easy to work around with a #!

@gshank
Copy link
Contributor

gshank commented Apr 22, 2022

Using a target context for the selector renderer was introduced in 1.0.0. The secret renderers were passed a context dictionary instead of a cli_var dictionary, so they were broken for var usage. In 1.0.5 we fixed the secret renders so that they were passed a cli_var dictionary instead of the context dictionary, but over-corrected and changed the selector renderer so that it also was just passed a cli_var dictionary. This PR changes the selector rendering to use the DbtProjectYamlRenderer, since the 'render_selectors' call is contained within it and needs the same rendering setup that it has.

@jtcohen6 jtcohen6 removed the triage label Apr 25, 2022
@jtcohen6 jtcohen6 added this to the v1.0.6 milestone Apr 25, 2022
@saraleon1
Copy link

+1 dbt Cloud enterprise customer. This is resulting in a failure to all jobs due to a failed dbt deps due to a 'target undefined' error

@jtcohen6
Copy link
Contributor

@ljhopkins2 @saraleon1 This fix is now available in v1.0.6-rc1 and v1.1.0-rc3. Those are available in dbt Cloud, respectively, as 1.0 (patch prerelease) and 1.1 (minor prerelease).

Thank you so much for reporting the regression, and helping us get to the bottom of it!

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

Successfully merging a pull request may close this issue.

4 participants