From 5ce19dd99ae5d206fc5ac807289fe474259256bc Mon Sep 17 00:00:00 2001 From: Truls <20932917+truls-p@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:09:13 +0000 Subject: [PATCH] Change metadata_vars `if not` to `if ... is None` (#37) Both None and {} evaluates to True when using if not metadata_vars. This caused us to loop over the environment variables unnecessarily. This provides a significant performance increase for large projects. --- .changes/unreleased/Under the Hood-20240123-194242.yaml | 6 ++++++ dbt_common/events/functions.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Under the Hood-20240123-194242.yaml diff --git a/.changes/unreleased/Under the Hood-20240123-194242.yaml b/.changes/unreleased/Under the Hood-20240123-194242.yaml new file mode 100644 index 00000000..a0cb7431 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240123-194242.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Change metadata_vars \`if not\` to \`if ... is None\` +time: 2024-01-23T19:42:42.95727089Z +custom: + Author: truls-p + Issue: "6073" diff --git a/dbt_common/events/functions.py b/dbt_common/events/functions.py index 60ef4d27..fde2219b 100644 --- a/dbt_common/events/functions.py +++ b/dbt_common/events/functions.py @@ -138,7 +138,7 @@ def fire_event(e: BaseEvent, level: Optional[EventLevel] = None) -> None: def get_metadata_vars() -> Dict[str, str]: global metadata_vars - if not metadata_vars: + if metadata_vars is None: metadata_vars = { k[len(_METADATA_ENV_PREFIX) :]: v for k, v in os.environ.items() if k.startswith(_METADATA_ENV_PREFIX) }