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!: include names of decorator argument references when building python env #3687

Merged
merged 7 commits into from
Jan 29, 2025

Conversation

georgesittas
Copy link
Contributor

@georgesittas georgesittas commented Jan 22, 2025

Fixes #3640

The main difficulty in solving the linked issue was making SQLMesh detect the stop_after_attempt reference, in order to extract and inject it into the python environment so it can be (de)serialized:

@retry(stop=stop_after_attempt(3))
def fetch_data():
    return "test data"

The decorator names themselves were already being picked up in the previous decorators helper. In this PR I expand that functionality by also searching for the decorator call arguments' references.

I implemented a new visitor class in order to limit the search to only the decorator sub-trees, instead of traversing the whole function tree. Without this, we'd have to do a nested walk within the root node traversal loop, leading to unnecessarily revisiting nodes under the decorator sub-trees.

Other than that, I also made sure to exclude callable instances of classes, because they can't be serialized. One such example is the tenacity.Retrying class (source). Letting these instances into the python environment doesn't "just work" unfortunately, because an error is raised once we reach this section, since there's no __name__ attribute in them.

I verified that this fix works for a project with the model of interest, as well as the example project we have under test_metaprogramming.py.

@georgesittas georgesittas requested review from izeigerman, tobymao and a team January 22, 2025 19:46
@georgesittas georgesittas force-pushed the jo/extract_decorator_dependencies branch from 2b77d3f to ff5ad46 Compare January 23, 2025 13:38
@georgesittas georgesittas force-pushed the jo/extract_decorator_dependencies branch 2 times, most recently from 4cedc91 to 48b8b0f Compare January 27, 2025 14:49
@georgesittas georgesittas force-pushed the jo/extract_decorator_dependencies branch 4 times, most recently from 906ff2c to 39d9f31 Compare January 28, 2025 18:39
@georgesittas georgesittas force-pushed the jo/extract_decorator_dependencies branch from 39d9f31 to 4a92b09 Compare January 29, 2025 18:42
@georgesittas georgesittas force-pushed the jo/extract_decorator_dependencies branch from 25d2d6d to 99a4d4f Compare January 29, 2025 20:16
@georgesittas georgesittas enabled auto-merge (squash) January 29, 2025 20:22
@georgesittas georgesittas merged commit 5039e88 into main Jan 29, 2025
21 checks passed
@georgesittas georgesittas deleted the jo/extract_decorator_dependencies branch January 29, 2025 20:25
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.

SQLMesh decorator processing fails with AttributeError for imported decorators
3 participants