-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add project name to default search packages #4114
Add project name to default search packages #4114
Conversation
We prefer macros in the project over the ones in the namespace (package)
Just going to close + re-open to re-trigger adapter integration tests, now that I've added the |
@jtcohen6 , I have troubles adding a test for this. I tried to add one to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a unit test for dispatch
over in dbt-redshift
here, I think we could borrow some of that logic and pull it here. I'll edit this comment with a bit of code in a moment
This is tricky, but let's get the current tests passing first
Ok, the new issue in the unit tests: This error is raised by |
Is 't because no macros are found or because the package is not found? raise_compiler_error(
f"Could not find package '{package_name}'"
) |
If a package has no macros defined, the package doesn't appear in dbt-core/core/dbt/context/macro_resolver.py Lines 69 to 72 in eace5b7
So per that error message, the package appears to be "missing." I think that's reasonable behavior for the macro resolver, although the error message could be clearer: Options for how
I'm leaning toward the latter. What do you think? |
I am wrapping my ahead around all inner dbt parts, so I can not judge well. What my gut feeling about this is, is that it is too tightly coupled: should the
It is raised there with the |
I agree with your reasoning there! My proposal would be, replace these lines with: except CompilationException as exc:
# we don't expect to find every macro we search for
pass That is to say, while normally the macro resolver should raise an error if
|
d52ea56
to
2544741
Compare
I tested it locally and it does the trick! Now, we should add a test for this. |
I have been looking at adding a test, I think the problem with adding it to the unit test is that the unit test assume no plugin/package (postgres, spark, redshift, etc.) is installed, but we pretend like it is because were getting a macro from that package ( I get the following error if I try this with the postgres plugin. E dbt.exceptions.InternalException: No plugin found for <MagicMock name='get_adapter().type()' id='4516255672'> Should and can we mock this? Or should this test be moved to a package? |
@JCZuurmond Ah ok, I don't think we're going to be able to figure that one very quickly. Let's add an integration test instead. There's a good starting point in |
9e72403
to
6558f71
Compare
6558f71
to
8bc2870
Compare
@jtcohen6 : ready to merge (if all tests pass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution @JCZuurmond!
* Add project name to default search packages We prefer macros in the project over the ones in the namespace (package) * Add change to change log * Use project_name instead of project * Raise compilation error if no macros are found * Update change log line * Add test for package macro override * Add JCZuurmond to contributor * Fix typos * Add test that should not over ride the package * Add doc string to tests
* Add project name to default search packages We prefer macros in the project over the ones in the namespace (package) * Add change to change log * Use project_name instead of project * Raise compilation error if no macros are found * Update change log line * Add test for package macro override * Add JCZuurmond to contributor * Fix typos * Add test that should not over ride the package * Add doc string to tests Co-authored-by: Cor <jczuurmond@protonmail.com>
def test_postgres_overrides(self): | ||
# the first time, the model doesn't exist | ||
self.run_dbt(expect_pass=False) | ||
self.run_dbt(expect_pass=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the second time be expect pass True ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a check in the model that raises an explicit error if the macro is overridden, so I believe it fails both times:
dbt-core/test/integration/016_macro_tests/override-get-columns-models/model.sql
Lines 1 to 5 in f20e83a
{% set result = adapter.get_columns_in_relation(this) %} | |
{% if execute and result != 'a string' %} | |
{% do exceptions.raise_compiler_error('overriding get_columns_in_relation failed') %} | |
{% endif %} | |
select 1 as id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained in the class docstring, the run in this test should fail because the override does not happen. We need the override to overrule the raise compile error that @jtcohen6 showed.
The macro in `override-postgres-get-columns-macros` does NOT override the
`get_columns_in_relation` macro because we tell dispatch to not look at the
postgres macros.
We prefer macros in the project over the ones in the namespace (package)
resolves #4106
Description
This changes will choose macros in the root project over the ones in the namespace.
Checklist
CHANGELOG.md
and added information about my change