Dbt: deps fails if a target has an undefined environment variable

Created on 28 Apr 2020  ·  2Comments  ·  Source: fishtown-analytics/dbt

Steps to reproduce

  1. Create a target with an undefined environment variable
  2. Run dbt deps

Expected behavior

dbt deps should still work — it doesn't need a valid target (right?)

Actual results

$ dbt deps
Running with dbt=0.16.1
Encountered an error:
Compilation Error
  Env var required but not provided: 'my_undefined_var'

When running on 0.15.1

$ dbt deps
Running with dbt=0.15.1
Warning: No packages were found in packages.yml

(ok so I don't actually have any packages)

System information

Which database are you using dbt with?
n/a - not a database thing

The output of dbt --version:
0.16.1 + 0.16.0

Additional context

Happy to get a wontfix tag slapped on this, just noticed this regression when some CI tests broke (related)

bug

Most helpful comment

For what's is worth, a fellow on Slack has suggested setting default values in the settings

Here is an example.

company:
  target: local
  outputs:
    local:
      type: postgres
      host: "{{ env_var('ENV_HOST', 'not-set') }}"
      user: "{{ env_var('ENV_USER', 'not-set') }}"
      pass: "{{ env_var('ENV_PASS', 'not-set') }}"
      port: "{{ env_var('ENV_PORT', 1000) }}"
      dbname: "{{ env_var('ENV_DBNAME', 'not-set') }}"
      schema: "{{ env_var('ENV_SCHEMA', 'not-set') }}"

Otherwise, Claire also suggested on Slack that you can force a --target when running dbt deps like so: dbt deps --target temporary_fix and create that entry in the configuration file:

company:
  target: local
  outputs:
    temporary_fix:
      type: postgres
      host: "random_value"
      user: "not-set"
      pass: "not-set"
      port: 1000
      dbname: "not-set"
      schema: "not-set"

Here is the Slack Thread in question.

Hope this was useful!

✌️

All 2 comments

+1, I have a related problem: dbt complains about an environment variable that is actually defined:

Env var required but not provided: 'USER'

For what's is worth, a fellow on Slack has suggested setting default values in the settings

Here is an example.

company:
  target: local
  outputs:
    local:
      type: postgres
      host: "{{ env_var('ENV_HOST', 'not-set') }}"
      user: "{{ env_var('ENV_USER', 'not-set') }}"
      pass: "{{ env_var('ENV_PASS', 'not-set') }}"
      port: "{{ env_var('ENV_PORT', 1000) }}"
      dbname: "{{ env_var('ENV_DBNAME', 'not-set') }}"
      schema: "{{ env_var('ENV_SCHEMA', 'not-set') }}"

Otherwise, Claire also suggested on Slack that you can force a --target when running dbt deps like so: dbt deps --target temporary_fix and create that entry in the configuration file:

company:
  target: local
  outputs:
    temporary_fix:
      type: postgres
      host: "random_value"
      user: "not-set"
      pass: "not-set"
      port: 1000
      dbname: "not-set"
      schema: "not-set"

Here is the Slack Thread in question.

Hope this was useful!

✌️

Was this page helpful?
0 / 5 - 0 ratings