-
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
[CT-3296] [Feature] Option to enforce 2-argument ref()
when referencing models from other packages/projects
#8951
Comments
cc: @jtcohen6, as we discussed package / project namespaces in the past |
ref()
when using models from installed packages
@jaklan would you mind double-checking this? When I tried this with dbt-core 1.6.6, two-argument We should update the docsWe should update the docs for two-argument Project setupHere's the files that I used:Directory structure
Project A
name: "package_a"
version: "1.0.0"
config-version: 2
profile: "sandcastle"
restrict-access: True # default is False
select 1 as id Project B
name: "package_b"
version: "1.0.0"
config-version: 2
profile: "sandcastle"
select * from {{ ref('model_a') }}
packages:
- local: ../package_a Try to compile in Project Bcd package_b
dbt deps
dbt compile Error log output
When I removed |
@dbeatty10 if I understand correctly, you haven't specified model access, so by default it's
Actually that part:
should be replaced with:
as |
Yeah, I see what you are saying! Indeed, in contraction to the original issue in #7446 and the docs here, the following code in the reprex below works fine instead of erroring. i.e. this says that it shouldn't:
And #7446 also says it shouldn't:
ReprexHere's the files that I used to demonstrate the issueDirectory structure
Project A
name: "package_a"
version: "1.0.0"
config-version: 2
profile: "sandcastle"
select 1 as id Project B
name: "package_b"
version: "1.0.0"
config-version: 2
profile: "sandcastle"
packages:
- local: ../package_a
select * from {{ ref('model_a') }} Compile in Project Bcd package_b
dbt deps
dbt compile --s model_b Output
|
@dbeatty10 thank you for the answer! I have also done a few additional tests in various combinations, here are the outcomes: Click to expand test scenarios
To sum up - an error is only raised in a situation when both conditions are met:
When Why? Let's imagine the 6. scenario described above - you work on Another example - we again start with the 6. scenario, but this time The only way to prevent such situations is to use 2-argument |
After reading this a few times, I've finally understood! The docs here say:
When perhaps we should more clearly say:
@jaklan It sounds like you want a compiler setting that is: "All references to models in other namespaces (projects/packages) must use two-argument
Personally, I'd vote for (3) — it's by far simplest. I'm going to relabel this from |
ref()
when using models from installed packagesref()
when referencing models from other packages/projects
ref()
when referencing models from other packages/projectsref()
when referencing models from other packages/projects
Hi @jtcohen6, thanks for the reply. Yes, we have two issues here:
Ad. 1: Looking at your proposal, I believe we can still improve it a bit.
That part imho doesn't cover the case when given model is not in the same namespace, but one candidate is in another namespace, so that's for example that scenario:
Maybe we should describe the resolution mechanism in a step-by-step form like:
Ad. 2: Exactly, that's the option I'm looking for. And fully agree we can't introduce breaking changes. About the 3 proposed variants - I would definitely vote for the second approach, because defining that as a runtime config could lead to completely different behaviour of given project depending on local settings. Let's look at that scenario:
If you enable the new runtime config - that's gonna fail (as expected). But if some developers in the project don't do that - it would still work. So we end up in a situation when different developers can use different |
I agree with this! I should clarify what I meant in option (3) above: I don't think it should be possible to enforce this differently based on the configs of the referencing project. It should be the same for all models in an invocation. And it should be a config that's defined, in version control, in the project code, so that it does not differ for different users/environments. |
So we agree on that one 😄 I just still miss what's the difference between 2nd and 3rd variant then, could you provide some example? |
Is this a new bug in dbt-core?
Current Behavior
As stated in dbt docs here:
The last sentence is incorrect though - if you use 1-argument
ref
and a model doesn't exist in the same package (namespace), but exists in a package installed as a dependency - no error is raised.Expected Behavior
I expect the behaviour specified in docs, so 1-argument
ref
should only work with models from the same package (namespace), but not with models (even the public ones) from installed packages. Such models should be referenced exclusively with two-argumentref
, otherwise - an error should be raised.If it's not a bug, but a mistake in documentation and you don't want to enable such behaviour by default - there should be an option provided to enforce it.
Steps To Reproduce
package_a
model_a
(public
orprotected
) inpackage_a
package_b
package_a
as a dependency inpackage_b
model_b
inpackage_b
asselect * from {{ ref('model_a') }}
dbt compile
inpackage_b
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
redshift
Additional Context
No response
The text was updated successfully, but these errors were encountered: