@@ -283,7 +283,7 @@ def build_env(
283
283
env : t .Dict [str , t .Tuple [t .Any , t .Optional [bool ]]],
284
284
name : str ,
285
285
path : Path ,
286
- is_metadata_obj : t . Optional [ bool ] = None ,
286
+ is_metadata_obj : bool = False ,
287
287
) -> None :
288
288
"""Fills in env dictionary with all globals needed to execute the object.
289
289
@@ -299,7 +299,7 @@ def build_env(
299
299
# We don't rely on `env` to keep track of visited objects, because it's populated in post-order
300
300
visited : t .Set [str ] = set ()
301
301
302
- def walk (obj : t .Any , name : str , is_metadata : t . Optional [ bool ] = None ) -> None :
302
+ def walk (obj : t .Any , name : str , is_metadata : bool = False ) -> None :
303
303
obj_module = inspect .getmodule (obj )
304
304
if obj_module and obj_module .__name__ == "builtins" :
305
305
return
@@ -320,7 +320,7 @@ def walk(obj: t.Any, name: str, is_metadata: t.Optional[bool] = None) -> None:
320
320
# The existing object in the env is "metadata only" but we're walking it again as a
321
321
# non-"metadata only" dependency, so we update this flag to ensure all transitive
322
322
# dependencies are also not marked as "metadata only"
323
- is_metadata = None
323
+ is_metadata = False
324
324
325
325
if hasattr (obj , c .SQLMESH_MACRO ):
326
326
# We only need to add the undecorated code of @macro() functions in env, which
@@ -380,7 +380,7 @@ def walk(obj: t.Any, name: str, is_metadata: t.Optional[bool] = None) -> None:
380
380
)
381
381
382
382
# The "metadata only" annotation of the object is transitive
383
- walk (obj , name , is_metadata_obj or getattr (obj , c .SQLMESH_METADATA , None ))
383
+ walk (obj , name , is_metadata_obj or getattr (obj , c .SQLMESH_METADATA , False ))
384
384
385
385
386
386
@dataclass
@@ -432,7 +432,11 @@ def value(
432
432
cls , v : t .Any , is_metadata : t .Optional [bool ] = None , sort_root_dict : bool = False
433
433
) -> Executable :
434
434
payload = _dict_sort (v ) if sort_root_dict else repr (v )
435
- return Executable (payload = payload , kind = ExecutableKind .VALUE , is_metadata = is_metadata )
435
+ return Executable (
436
+ payload = payload ,
437
+ kind = ExecutableKind .VALUE ,
438
+ is_metadata = is_metadata or None ,
439
+ )
436
440
437
441
438
442
def serialize_env (env : t .Dict [str , t .Any ], path : Path ) -> t .Dict [str , Executable ]:
@@ -447,6 +451,9 @@ def serialize_env(env: t.Dict[str, t.Any], path: Path) -> t.Dict[str, Executable
447
451
serialized = {}
448
452
449
453
for k , (v , is_metadata ) in env .items ():
454
+ # We don't store `False` for `is_metadata` to reduce the pydantic model's payload size
455
+ is_metadata = is_metadata or None
456
+
450
457
if isinstance (v , LITERALS ) or v is None :
451
458
serialized [k ] = Executable .value (v , is_metadata = is_metadata )
452
459
elif inspect .ismodule (v ):
0 commit comments