@@ -283,7 +283,7 @@ def build_env(
283283 env : t .Dict [str , t .Tuple [t .Any , t .Optional [bool ]]],
284284 name : str ,
285285 path : Path ,
286- is_metadata_obj : t . Optional [ bool ] = None ,
286+ is_metadata_obj : bool = False ,
287287) -> None :
288288 """Fills in env dictionary with all globals needed to execute the object.
289289
@@ -299,7 +299,7 @@ def build_env(
299299 # We don't rely on `env` to keep track of visited objects, because it's populated in post-order
300300 visited : t .Set [str ] = set ()
301301
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 :
303303 obj_module = inspect .getmodule (obj )
304304 if obj_module and obj_module .__name__ == "builtins" :
305305 return
@@ -320,7 +320,7 @@ def walk(obj: t.Any, name: str, is_metadata: t.Optional[bool] = None) -> None:
320320 # The existing object in the env is "metadata only" but we're walking it again as a
321321 # non-"metadata only" dependency, so we update this flag to ensure all transitive
322322 # dependencies are also not marked as "metadata only"
323- is_metadata = None
323+ is_metadata = False
324324
325325 if hasattr (obj , c .SQLMESH_MACRO ):
326326 # 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:
380380 )
381381
382382 # 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 ))
384384
385385
386386@dataclass
@@ -432,7 +432,11 @@ def value(
432432 cls , v : t .Any , is_metadata : t .Optional [bool ] = None , sort_root_dict : bool = False
433433 ) -> Executable :
434434 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+ )
436440
437441
438442def 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
447451 serialized = {}
448452
449453 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+
450457 if isinstance (v , LITERALS ) or v is None :
451458 serialized [k ] = Executable .value (v , is_metadata = is_metadata )
452459 elif inspect .ismodule (v ):
0 commit comments