question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

bug: strict_env_var_mode feature flag not respected?

See original GitHub issue

Meltano Version

2.10

Python Version

3.7

Bug scope

Configuration (settings parsing, validation, etc.)

Operating System

Amaon Linux

Description

I think the change in strict_env_var_mode that came out w 2.10 (https://github.com/meltano/meltano/pull/6971) is causing issues for me with pipelinewise/target-snowflake. Not 100% sure if its a real bug or somethingโ€™s messed up in my setup that was revealed by that change. But upon upgrade to 2.10, all my runs started failing with "Environment variable 'TARGET_SNOWFLAKE_SCHEMA' referenced but not set. I donโ€™t think Iโ€™ve ever set that variable and I dontโ€ฆ think(?) that plugin is actually expecting that env var? I am also noticing that this error gets thrown only for schedules that are defined in the โ€œlegacy ETLโ€ syntax, not via โ€œjobsโ€.

Code

2022-11-16T22:36:29.972001Z [error    ] ("Environment variable 'TARGET_SNOWFLAKE_SCHEMA' referenced but not set", 'Make sure the environment variable is set') 
Traceback (most recent call last):
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/utils/__init__.py", line 495, in subst
    val = str(env[var])
KeyError: 'TARGET_SNOWFLAKE_SCHEMA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/logging/output_logger.py", line 201, in redirect_logging
    yield
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/cli/elt.py", line 257, in _redirect_output
    yield
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/cli/elt.py", line 271, in _run_elt
    elt_context = context_builder.context()
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/elt_context.py", line 467, in context
    env.update(loader.env)
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/elt_context.py", line 77, in env
    return {**self.plugin.info_env, **self.config_env()}
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/elt_context.py", line 68, in config_env
    return self.settings_service.as_env(session=self.session, **kwargs)
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/settings_service.py", line 287, in as_env
    for _, config in self.config_with_metadata(*args, **kwargs).items():
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/settings_service.py", line 240, in config_with_metadata
    **kwargs,
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/settings_service.py", line 362, in get_with_metadata
    value, env=expandable_env, raise_if_missing=env_var_strict_mode
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/utils/__init__.py", line 511, in expand_env_vars
    return subst(fullmatch)
  File "/home/ec2-user/meltano/venv/lib64/python3.7/site-packages/meltano/core/utils/__init__.py", line 504, in subst
    raise EnvironmentVariableNotSetError(e.args[0])
meltano.core.utils.EnvironmentVariableNotSetError: ("Environment variable 'TARGET_SNOWFLAKE_SCHEMA' referenced but not set", 'Make sure the environment variable is set')

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
qbattencommented, Nov 18, 2022
  1. config dump & grep.
(venv) [ec2-user@redact meltano-main]$ meltano config meltano | grep "strict_env_var_mode"
2022-11-17T17:24:06.807913Z [info     ] Environment 'prod' is active
    "strict_env_var_mode": false`
  1. Wasnโ€™t able to get to this yet, I figured Iโ€™d post this for now anyway

  2. Itโ€™s not set in the .env file, nor in meltano.yml. Just queried the system DB and the plugin_settings table has 0 rows.

0reactions
qbattencommented, Dec 1, 2022

Actually this problem does seem to be occurring with jobs too.

I worked around it by setting TARGET_SNOWFLAKE_SCHEMA in my dotenv file. The variable isnโ€™t actually used by pipelinewise/target-snowflake so it doesnt affect the schema written to.

Still not sure what the root cause is, but it is definitely still happening with MELTANO_FF_STRICT_ENV_VAR_MODE=false in dotenv. And I also confirmed that the way Iโ€™m setting it is indeed changing the config; When I set it to true, the output of meltano config meltano | grep strict does show it changing to true.

Here's a debug error printout (heavily redacted) that happens to also show that strict_env_var_mode is indeed set to false. Maybe this'll help w diagnosis?

 [debug    ] Creating engine '<meltano.core.project.Project object at 0x12341234>@postgresql://xxxxxxxxxxx'
 [info     ] The default environment 'dev' will be ignored for `meltano schedule`. To configure a specific environment, please use the option `--environment=<environment name>`.
 [debug    ] Creating engine '<meltano.core.project.Project object at 12341234>@postgresql://xxxxxxxxxxxxx'
 [info     ] Environment 'dev' is active
 [debug    ] expanding job to tasks         job_name=job-xxxxxxxx-0 tasks=['xxxxxxxx-0', 'target-snowflake-xxxxxxxx']
 [debug    ] Encoding detection: ascii is most likely the one.
 [debug    ] Found plugin parent            parent=tap-postgres plugin=tap-postgres-xxxxxx source=discovery
 [debug    ] Found plugin parent            parent=tap-postgres-xxxxxxxx plugin=xxxxxxxx-0 source=inherited
 [debug    ] found plugin in cli invocation plugin_name=xxxxxxxx-0
 [debug    ] Found plugin parent            parent=target-snowflake plugin=target-snowflake source=discovery
 [debug    ] Found plugin parent            parent=target-snowflake plugin=target-snowflake-xxxxxxxx source=inherited
 [debug    ] found plugin in cli invocation plugin_name=target-snowflake-xxxxxxxx
 [debug    ] head of set is extractor as expected block=<meltano.core.plugin.project_plugin.ProjectPlugin object at 12341234>
 [debug    ] found block                    block_type=loaders index=1
 [debug    ] blocks                         idx=1 offset=0
 [debug    ] Environment variable 'TARGET_SNOWFLAKE_SCHEMA' referenced but not set. Make sure the environment variable is set. 
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ [1;31mTraceback [1;2;31m(most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ xxxxxxxxxxxxxxx/venv/lib64/python3.7/site-packages/meltano/core/utils/[1;33m__init__.py:49 โ”‚
โ”‚ 5 in subst                                                                                       โ”‚
โ”‚                                                                                                  โ”‚
โ”‚   492 โ”‚   โ”‚   try:                                                                               โ”‚
โ”‚   493 โ”‚   โ”‚   โ”‚   # the variable can be in either group                                          โ”‚
โ”‚   494 โ”‚   โ”‚   โ”‚   var = next(var for var in match.groups() if var)                               โ”‚
โ”‚ โฑ 495 โ”‚   โ”‚   โ”‚   val = str(env[var])                                                            โ”‚
โ”‚   496 โ”‚   โ”‚   โ”‚                                                                                  โ”‚
โ”‚   497 โ”‚   โ”‚   โ”‚   if not val:                                                                    โ”‚
โ”‚   498 โ”‚   โ”‚   โ”‚   โ”‚   logger.debug(f"Variable '${var}' is empty.")                               โ”‚
โ”‚                                                                                                  โ”‚
โ”‚ โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚
โ”‚ โ”‚              env = {                                                                         โ”‚ โ”‚
โ”‚ โ”‚                    โ”‚   'MELTANO_FF_STRICT_ENV_VAR_MODE': 'false',                            โ”‚ โ”‚
โ”‚ โ”‚                    โ”‚   'MELTANO_DATABASE_URI':'postgresql:// xxxxxxxxxxxxxxxxxxxxxxxxxxxx    โ”‚ โ”‚
โ”‚ โ”‚                    โ”‚   ... +123                                                              โ”‚ โ”‚
โ”‚ โ”‚                    }                                                                         โ”‚ โ”‚
โ”‚ โ”‚            match = <[1;95mre.Match object; span=[1;39m(0, 24[1;39m), match='$TARGET_SNOWFLAKE_SCHEMA'>         โ”‚ โ”‚
โ”‚ โ”‚ raise_if_missing = 'false'                                                                   โ”‚ โ”‚
โ”‚ โ”‚              var = 'TARGET_SNOWFLAKE_SCHEMA'                                                 โ”‚ โ”‚
โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
[1;91mKeyError: 'TARGET_SNOWFLAKE_SCHEMA'

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 6 Types of Feature Flags You'll Meet at Optimizely: Bug Fix
Using a feature flag to bug fix is the most rare flag we use here at Optimizely. We do not use feature flags...
Read more >
Feature flags - GitLab Docs
With feature flags, you can deploy your application's new features to production in smaller batches. You can toggle a feature on and off...
Read more >
Avoid bugs in production: The use of feature flags
Feature flags are pieces of data that are stored remotely in a way that your company can decide whether it should be part...
Read more >
Feature Flags Best Practices (Feature Toggles) - Harness
Testing in production, trunk-based development, using feature flags by default - these are all Feature Flags Best Practices.
Read more >
Feature Toggles (aka Feature Flags) - Martin Fowler
Hardcoded Toggle Configuration. The most basic technique - perhaps so basic as to not be considered a Feature Flag - is to simply...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found