@@ -582,7 +582,9 @@ def test_func(x: int, y: str) -> str:
582582 assert call_arg ["class" ] == f"{ FunctionTask .__module__ } .{ FunctionTask .__name__ } "
583583 assert call_arg ["metadata" ]["func_name" ] == "test_func"
584584 assert call_arg ["metadata" ]["func_module" ] == test_func .__module__
585- assert "func_file" not in call_arg ["metadata" ] # Not __main__ module
585+ # func_file is now always included to support modules not in Python path
586+ assert "func_file" in call_arg ["metadata" ]
587+ assert call_arg ["metadata" ]["func_file" ].endswith ("test_dispatcher.py" )
586588
587589 def test_serialize_function_task_handles_main_module_with_file_path (self ) -> None :
588590 # Arrange
@@ -673,9 +675,13 @@ def test_serialize_function_task_handles_main_module_type_error(self) -> None:
673675 task ._current_attempt = 0
674676 task ._dispatched_at = datetime (2024 , 1 , 1 , 12 , 0 , 0 , tzinfo = UTC )
675677
676- # Act & Assert - should raise AttributeError when trying to access __code__
677- with raises (AttributeError ):
678- dispatcher ._task_serializer .serialize (task )
678+ # Act - should handle AttributeError gracefully and not include func_file
679+ dispatcher ._task_serializer .serialize (task )
680+
681+ # Assert - func_file should not be present when __code__ is unavailable
682+ mock_serializer .serialize .assert_called_once ()
683+ call_arg = mock_serializer .serialize .call_args [0 ][0 ]
684+ assert "func_file" not in call_arg ["metadata" ]
679685
680686 def test_serialize_function_task_excludes_func_from_params (self ) -> None :
681687 # Arrange
0 commit comments