Fix: serialization regression with sqlmesh.core.dialect.normalize_model_name #3025
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
sqlmesh.core.dialect.normalize_model_name
uses lru_cache.https://github.com/z3z1ma/sqlmesh/blob/0b3aeac041b280cb79bee51613648a9fce4c5646/sqlmesh/core/dialect.py#L960-L981
Serialization fails on this object when calling inspect.getfile
This is a common import. This bug would've been introduced by #3008 as I don't think there was an lru cache there before
I added a failing test by simply referencing the function in question in the main_func in test_metaprogramming
I fixed it by using
inspect.unwrap
to safely unwrap to func specifically in the getfile call. This returns the correct file path.https://docs.python.org/3/library/inspect.html#inspect.unwrap
I have confirmed tests pass and this works on my production project too (whereas before it was bugged/un-runnable).
In the future, due to the fact that getfile can throw at all, we should probably add a try except unless we think our builtin guard is good enough (though this obviously slipped through).