Skip to content

fix: only patch ref protection when a dbt-loom config is present - #174

Merged
adrienneyager merged 1 commit into
adrienneyager:mainfrom
karthikkarnam:fix/conditional-ref-protection-patch
May 7, 2026
Merged

adrienneyager merged 1 commit into
adrienneyager:mainfrom
karthikkarnam:fix/conditional-ref-protection-patch

Conversation

@karthikkarnam

Copy link
Copy Markdown
Contributor

Summary

Fixes #173.

When dbt-loom is installed as a transitive dependency but no dbt_loom.config.yml exists, _patch_ref_protection() was still being applied unconditionally. The shims in shims.py are more permissive than dbt's originals for is_invalid_private_ref:

  • A singular test with no {{ config(group=...) }} block has node.group = None, so the first condition in the shim is always False.
  • If the nodes share a package, the restrict_access condition is also False.
  • The shim returns False (no error) where dbt's original would return True.

The existing if self.config is not None guard inside dependency_wrapper doesn't help — the wrapped function still calls the weaker shim once the patch has been applied.

Fix

Guard _patch_ref_protection() on self.config is not None. When no config file exists, dbt-loom isn't being used for cross-project manifest injection, so there's no reason to weaken dbt's built-in access enforcement.

if self.config is not None:
    self._patch_ref_protection()

Test plan

  • Existing test suite still passes (pytest tests/)
  • Confirmed the bug reproduces on main in a project where dbt-loom is a transitive dep with no config file
  • Confirmed Z002 is now raised correctly after the fix

When dbt-loom is installed as a transitive dependency and no dbt_loom.config.yml exists, the plugin still patchedis_invalid_private_ref / is_invalid_protected_ref with shims that are more permissive than dbt's originals. This silently suppressed Z002 dbt-loom installed surfaced the error. Guard the patch on self.config is not None so dbt's built-in enforcement is preserved when loom isn't actually being used.
Closes adrienneyager#173

@adrienneyager adrienneyager left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. When dbt-loom has no config, it shouldn't monkey-patch dbt's ref protection shims, and the guard mirrors the pattern already used in. Approved ✅

adrienneyager

This comment was marked as duplicate.

@adrienneyager adrienneyager added the bug Something isn't working label May 7, 2026
@adrienneyager
adrienneyager merged commit b6ba88d into adrienneyager:main May 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_patch_ref_protection() applied unconditionally suppresses Z002 when no config file is present

2 participants