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

Reference model from a package #89

Open
mdimercurio opened this issue Sep 7, 2022 · 6 comments
Open

Reference model from a package #89

mdimercurio opened this issue Sep 7, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@mdimercurio
Copy link

I am trying to write a unit test for a model that depends on a model from a different package.

I tried referencing the model name directly in mock_ref and got the following error:

Node [dbt_project].[model] not found.

> in macro raise_error (macros/utils.sql)
> called by macro model_node (macros/utils.sql)
> called by macro graph_node (macros/utils.sql)
> called by macro build_mocks_and_expectations (macros/tests.sql)
> called by macro test (macros/tests.sql)

When trying to reference the package with mock_ref([package_name], [model_name]), I got:

'str object' has no attribute 'items'

> in macro merge_configs (macros/utils.sql)
> called by macro build_mocks_and_expectations (macros/tests.sql)
> called by macro test (macros/tests.sql)
> called by macro merge_jsons (macros/utils.sql)
@cdiniz
Copy link
Collaborator

cdiniz commented Sep 8, 2022

Hi @mdimercurio.
We don't have this feature yet, but it makes sense to add it since 'ref' supports this functionality.
We don't have much time in the next few weeks, but we'll address this later.
Meanwhile, feel free to contribute with a pr if you will.

Thank you

@mdimercurio
Copy link
Author

Hi @cdiniz. Thanks for the quick follow up.

I'll try to look into it in my side. I haven't looked much into the package's code so I might have a few questions for you as I dig into it

@asadbadal
Copy link

@mdimercurio +1 on this issue, any progress you might've made that you can share?

@cdiniz cdiniz added the enhancement New feature or request label Mar 18, 2023
@SimonCarryer
Copy link

SimonCarryer commented Jul 9, 2023

Hello! I was thinking about having a go at a PR for this, but to be honest it's WAY more complex than anything else I've done in dbt. I can see that the issue is with the graph_node_by_prefix macro and its cousins. They're using model.package_name which refers to the package of the model being run, not the model being referenced.

I can see a few ways around this, but I am a bit worried about unforeseen consequences. Since model names must be unique, is there a risk in just looking for the first model with a matching name? How does the ref function do this?

Is there any problem with doing something like this? It feels wrong, somehow.

{% macro graph_node_by_prefix (prefix, name) %}
  {% set matches = graph.nodes.values() | selectattr("name", "equalto", name) | selectattr("resource_type", "equalto", prefix) | list %}
  {{ return (matches[0])}}
{% endmacro %}

@cdiniz
Copy link
Collaborator

cdiniz commented Apr 15, 2024

Hi there, we are doing a clean-up of old/inactive Issues.
Happy to open again if there is a need for that.
Thank you for collaboration!

@cdiniz cdiniz closed this as completed Apr 15, 2024
@SimonCarryer
Copy link

Very much still needed by me! Maybe I'll get around to a PR for it too!

@cdiniz cdiniz reopened this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants