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

compile inline query doesn't add node #7326

Merged
merged 3 commits into from
Apr 12, 2023
Merged

Conversation

ChenyuLInx
Copy link
Contributor

@ChenyuLInx ChenyuLInx commented Apr 11, 2023

Related to #6358
When compile a inline node, we add one additional node to the manifest. That node should be removed when compile is done.

I tried but couldn't find a way to add a test for this. was hoping to have one function to remove the line node and validate it is being called when running inline query but couldn't mock because dbt.task.compile is not a package.
Didin't try hard enough last time, added test

@ChenyuLInx ChenyuLInx added the Skip Changelog Skips GHA to check for changelog file label Apr 11, 2023
@ChenyuLInx ChenyuLInx requested review from stu-k, aranke, iknox-fa and a team April 11, 2023 19:12
@cla-bot cla-bot bot added the cla:yes label Apr 11, 2023
@ChenyuLInx ChenyuLInx requested a review from MichelleArk April 11, 2023 23:29
Copy link
Contributor

@stu-k stu-k left a comment

Choose a reason for hiding this comment

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

Looks straightforward to me 👍

def after_run(self, adapter, results):
# remove inline node from manifest
if self._inline_node_id:
self.manifest.nodes.pop(self._inline_node_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to reset _inline_node_id as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I had it in some version then lost it due to some branch moving around.

Also added test!

@ChenyuLInx ChenyuLInx requested a review from a team as a code owner April 12, 2023 15:04
["compile", "--inline", "select * from {{ ref('second_model') }}"],
populate_cache=False,
)
assert len(manifest.nodes) == 4
Copy link
Contributor

Choose a reason for hiding this comment

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

@ChenyuLInx ChenyuLInx requested review from MichelleArk and stu-k April 12, 2023 15:09
@@ -40,6 +40,10 @@ def compile(self, manifest):


class CompileTask(GraphRunnableTask):
# We add a new inline node to the manifest during initialization
# it should be removed before the task is complete
_inline_node_id = None
Copy link
Contributor

@MichelleArk MichelleArk Apr 12, 2023

Choose a reason for hiding this comment

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

It feels a bit off to have a non-constant, instance-specific representation state as a class attribute. Is there a reason this isn't defined on the instance instead via an __init__ override?

Copy link
Member

@aranke aranke left a comment

Choose a reason for hiding this comment

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

Should we abstract node creation/deletion into a context manager function decorator?

https://docs.python.org/3/library/contextlib.html#using-a-context-manager-as-a-function-decorator

@ChenyuLInx ChenyuLInx merged commit 602535f into main Apr 12, 2023
@ChenyuLInx ChenyuLInx deleted the cl/compile_query_work branch April 12, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants