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

[Bug] Behavior flags should take the default value when the project file is not loaded #338

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mikealfare
Copy link
Contributor

Problem

We don't always get the flags property on the config object that gets used to create a BaseAdapter instance. This happens whenever project.yml is not loaded. In particular, this happens during dbt debug, which is meant to be a quick check of whether we can connect to a database; this command only requires profile.yml.

The decision was initially made to not load any behavior flags in the scenarios where project.yml was not loaded. The rationale there was that we did not want to return one value for a behavior flag when project.yml is not loaded (hence the default) and another value for the behavior flag when project.yml is loaded (the default, potentially overridden by the user). However, in the former scenario, referencing the behavior flag at all results in a CompilationError since the flag does not exist on BaseAdapter.behavior. This is not desirable behavior either.

Solution

While the behavior flags are loaded onto BaseAdapter.behavior dynamically, the object should always have the same flags available. Since the user's overrides are not available when project.yml is not loaded, we should act as if project.yml was loaded, but without a flags node. In other words, we should simply assume the default values when we don't get a flags attribute.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development, and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX

@mikealfare mikealfare self-assigned this Oct 24, 2024
@mikealfare mikealfare requested a review from a team as a code owner October 24, 2024 19:44
@cla-bot cla-bot bot added the cla:yes label Oct 24, 2024
Copy link

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

]


def test_register_behavior_flags(adapter):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same test as in ./test_behavior_flags.py, but with flags removed from the config fixture above, and swapping the expected values for the two cases where the user override changes the result.

# we don't always get project flags, for example, the project file is not loaded during `dbt debug`
# in that case, load the default values for behavior flags to avoid compilation errors
# this mimics not loading a project file, or not specifying flags in a project file
user_overrides = getattr(self.config, "flags", {})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is effectively the same as swapping [] for flags on line 308, but doing this reads much more cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants