-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[CT-1146] [Bug] providers.py raises unhelpful error if dispatch provides package name that doesn't exist #5801
Comments
I think the fix is fine. Please submit a PR. Creating the test will probably be a lot more work than the fix :) |
I prefer the fix like this (which I didn't actually try out 😅): search_packages = None
if namespace is None:
search_packages = [None]
elif isinstance(namespace, str):
search_packages = self._adapter.config.get_macro_search_order(namespace)
if not search_packages and namespace in self._adapter.config.dependencies:
search_packages = [self.config.project_name, namespace]
else:
raise CompilationException(
f"In adapter.dispatch, got a {type(namespace)} macro_namespace argument "
f'("{macro_namespace}"), but macro_namespace should be None or a string.'
)
if search_packages is None:
search_packages = [None] The first line ensures that there is an initial default value for Even better:
def _get_search_packages(self, namespace: Optional[str] = None):
...
return search_packages And then call it: search_packages = self._get_search_packages(macro_namespace) Then this extraneous line can probably be removed too: namespace = macro_namespace |
+1 got same error on 1.5.0. core |
Thanks for sharing that @Gunnnn 👍 We've got a PR open to fix this which probably wouldn't be included any earlier than in v1.6. |
Any workarounds if we can't yet upgrade to 1.6? |
@pjatx the fix is really just providing a better error message to help find the source of the problem. Either way, you'll still need to find the code that is misconfigured and fix it. Are you getting this problem when installing a dbt project / package provided by someone else? Or are you getting it while doing some development on your own dbt project / package? Here's an example of some simple misconfigured code that you can try out for yourself on any version of dbt:
{% macro cowsay() %}
{{ return(adapter.dispatch('cowsay', 'farm_utils')()) }}
{%- endmacro %}
{% macro default__cowsay() %}
'moo'
{% endmacro %} 👀 Note the difference between
name: 'test_utils'
version: '1.0'
config-version: 2
profile: 'default'
macro-paths: ["macros"] Once you've made the fix, then building a model like the following should work again without error:
select {{ test_utils.cowsay() }} as cowsay |
@dbeatty10 Thanks for the quick reply! So in my case, it's coming from the following macro (if I remove it error goes away).
Looks like it's related to the snowplow adapter, but that actually even being used in the project. Any insights appreciated! |
Is this a new bug in dbt-core?
Current Behavior
I want to preface this by saying I am not surprised that no one has run into this bug before. It takes a special kind of person to make changes to every macro reference in their package and then forget to update the package name in the dispatch line. That being said, here is the bug.
If the adapter.dispatch provides the name of a package that doesn't exist, the error handling build into providers.py doesn't account for this pattern.
Example: The namespace provided
metrics
exists so it doesn't go into the first path. In the second path, it looks for the namespace inget_macro_search_order
but that can't complete because the namespace doesn't exist in thedbt_projects
path. The end result is returning a None object.This None object then can't be iterated in line 167:
This returns an unhelpful error message shown in relevant log output.
Potential Fix?
@dbeatty10 and I were able to solve this problem by adding another path after line 154:
This allows the search_packages variable to be iterated over with and helps raise a much more helpful error message around what is going wrong.
Expected Behavior
This error message
Steps To Reproduce
Loom explaining and showing issue: https://www.loom.com/share/347a5dc783cc45f2be5c8d7eede01622
Relevant log output
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
Happy to submit the fix if the team thinks that the proposed fix above matches what the team thinks it is good code!
The text was updated successfully, but these errors were encountered: