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

fix save_test_history macro to work when a model depends_on a source with the same name #106

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

Conversation

akshaykarle
Copy link
Contributor

@akshaykarle akshaykarle commented Nov 2, 2022

What

Describe what the change is solving
By using the separated source and ref lists, we can ensure that we fetch the correct node name for the test.

How

passing the additional depends_on_nodes parameter to priv_full_name_from_depends fixes the failing error as it now fetches the correct node for the corresponding source or model


{% for full_name in node.depends_on.nodes %}
{% set node_name = full_name.split('.')[-1] %}
{% if node_name == name %}
{% set node_type = full_name.split('.')[0] %}
Copy link
Member

Choose a reason for hiding this comment

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

Would that work for seed node type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure actually, didn't have any seed data in our project so never tested it. Would that come as a separate type here or just as a source or something? I can have a play with seed data if you are not aware and update the PR if needed.

Copy link
Member

Choose a reason for hiding this comment

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

@akshaykarle Not 100% sure if seeds are a separate type. If you could play with it this would be great, we also have seeds in our tests so those would likely detect that. (We should add the ability to run those on PR's external contributors, as it's a bit hard to test this now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, I will test it then and update here in the next few days. and yes, if the tests could run on PR's that would be amazing.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, will look into running them ;)

Copy link
Member

Choose a reason for hiding this comment

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

@maciejklimek Maybe something you would like to look into?

Copy link
Contributor Author

@akshaykarle akshaykarle Feb 23, 2023

Choose a reason for hiding this comment

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

hey @mateuszklimek I finally got some time to test out this issue with seed data. It looks like we cannot have this issue with seed data since we specifically pull only refs and sources based on the regex -

{% set any_refs = modules.re.findall("ref\(\'(?P<name>.*)\'\)", el.node.test_metadata.kwargs['model']) %}
I did also test adding a seed node with the same name as the model but dbt compile itself fails because of the name conflict which didn't happen with source and model so i think we are good on this? Please let me know if there is anything else I can do to help you test and merge this. Would've also been nice to be able to run the integration tests but I suppose that would need more changes which can be a separate PR and I'm not familiar with your CI/CD process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @mateuszklimek this has now been improved and it should work with everything since we pull the node from the existing depends_on list

@akshaykarle
Copy link
Contributor Author

hey @mateuszklimek did you or someone else get a chance to review this?

akshaykarle and others added 6 commits June 21, 2023 13:50
…with the same name

* Without checking the node_type, a model could match a source with the same name and the macro would error out trying to get the database on that node which is not present for a source
* Fixes issue: re-data/re-data#371
…safe

fix save_test_history macro to work when a model (snapshot or model) depends_on a source with the same name
@akshaykarle akshaykarle force-pushed the fix-bug-save-history-failure-371 branch from 6b04f3f to 4719c98 Compare June 22, 2023 14:30
@akshaykarle
Copy link
Contributor Author

hey @mateuszklimek is this project still alive? would be good to merge this if possible. Thanks!

@davidzajac1
Copy link
Collaborator

hey @mateuszklimek is this project still alive? would be good to merge this if possible. Thanks!

@akshaykarle yes the project is back on track now. I just tested your changes and it looks like they break another fix that was recently merged see #113

I tried adding this line 'compiled_sql': el.node.compiled_sql or el.node.compiled_code or none, to your changes but after doing that I was no longer able to see the Compile SQL section in the UI.

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

Successfully merging this pull request may close these issues.

4 participants