@@ -888,6 +888,7 @@ async def create_local_run(
888
888
from prefect .utilities ._engine import dynamic_key_for_task_run
889
889
from prefect .utilities .engine import (
890
890
collect_task_run_inputs_sync ,
891
+ record_task_assets ,
891
892
)
892
893
893
894
if flow_run_context is None :
@@ -928,7 +929,7 @@ async def create_local_run(
928
929
929
930
store = await ResultStore (
930
931
result_storage = await get_or_create_default_task_scheduling_storage ()
931
- ).update_for_task (task )
932
+ ).update_for_task (self )
932
933
context = serialize_context ()
933
934
data : dict [str , Any ] = {"context" : context }
934
935
if parameters :
@@ -995,55 +996,10 @@ async def create_local_run(
995
996
)
996
997
997
998
# Record task assets after creating the task run
998
- self .task_run = task_run
999
- self ._record_task_assets ()
999
+ record_task_assets (self , task_run )
1000
1000
1001
1001
return task_run
1002
1002
1003
- def _record_task_assets (self ) -> None :
1004
- """Record direct assets and conditionally propagate upstream assets based on task type."""
1005
- ctx = FlowRunContext .get ()
1006
- if not ctx or not hasattr (self , "task_run" ) or not self .task_run :
1007
- return
1008
-
1009
- direct_assets = []
1010
-
1011
- # TODO don't do hasattr
1012
- if hasattr (self , "asset_deps" ) and self .asset_deps :
1013
- from prefect .assets import Asset
1014
-
1015
- for asset in self .asset_deps :
1016
- asset_obj = asset if isinstance (asset , Asset ) else Asset (key = asset )
1017
- direct_assets .append (asset_obj )
1018
-
1019
- if hasattr (self , "assets" ):
1020
- direct_assets .extend (self .assets )
1021
- assets_for_downstream = self .assets [:]
1022
- else :
1023
- upstream_assets = self ._get_upstream_assets_from_inputs ()
1024
- assets_for_downstream = direct_assets + list (upstream_assets )
1025
-
1026
- ctx .task_run_assets [self .task_run .id ] = assets_for_downstream
1027
-
1028
- def _get_upstream_assets_from_inputs (self ) -> set [Any ]:
1029
- """Extract upstream assets from task inputs"""
1030
- if (
1031
- not hasattr (self , "task_run" )
1032
- or not self .task_run
1033
- or not self .task_run .task_inputs
1034
- ):
1035
- return set ()
1036
-
1037
- upstream_assets = set ()
1038
- for input_list in self .task_run .task_inputs .values ():
1039
- # TODO make sure we're only checking TaskRunResult
1040
- # TODO I think I can just get rid of this whole method...
1041
- for task_input in input_list :
1042
- if hasattr (task_input , "assets" ) and task_input .assets :
1043
- upstream_assets .update (task_input .assets )
1044
-
1045
- return upstream_assets
1046
-
1047
1003
@overload
1048
1004
def __call__ (
1049
1005
self : "Task[P, NoReturn]" ,
0 commit comments