Skip to content

Fix: python serialization edge case#4074

Merged
georgesittas merged 1 commit intomainfrom
jo/metaprogramming_edge_case
Apr 2, 2025
Merged

Fix: python serialization edge case#4074
georgesittas merged 1 commit intomainfrom
jo/metaprogramming_edge_case

Conversation

@georgesittas
Copy link
Contributor

@georgesittas georgesittas commented Apr 2, 2025

This PR addresses a bug in the Python code serialization logic. When walking objects and looking up function globals, we only add them to the environment if the fetched objects are not falsey, which leads to excluding falsey primitives such as 0, False and None. A minimally-reproducible example for this is shown below:

import pandas as pd
from sqlmesh import model

Z = 0

@model(name="foo", columns={"id": "int"})
def entrypoint(context, *args, **kwargs):
    return pd.DataFrame({"id": [Z]})

# Failed models
# 
#  "foo"
#
#    File 'models/test.py' (or imported file), line 2, in entrypoint
#        def entrypoint(context, *args, **kwargs):
#            return pd.DataFrame({'id': [Z]})
#          NameError: name 'Z' is not defined
#
# Error: Plan application failed.

No additional context here. I was simply playing around locally and came across this issue, so figured I'd fix it.

@georgesittas georgesittas requested review from a team and tobymao April 2, 2025 11:57
@georgesittas georgesittas force-pushed the jo/metaprogramming_edge_case branch from a3b8880 to e0caead Compare April 2, 2025 12:24
@georgesittas georgesittas merged commit 4bf7a05 into main Apr 2, 2025
22 checks passed
@georgesittas georgesittas deleted the jo/metaprogramming_edge_case branch April 2, 2025 14:19
afzaljasani pushed a commit that referenced this pull request Apr 8, 2025
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.

2 participants