shahar1 commented on code in PR #41039: URL: https://github.com/apache/airflow/pull/41039#discussion_r1702318915
########## airflow/utils/python_virtualenv.py: ########## @@ -149,3 +157,74 @@ def write_python_script( ) template = template_env.get_template("python_virtualenv_script.jinja2") template.stream(**jinja_context).dump(filename) + + +def context_to_json(context: Context) -> str: + from airflow.models.param import ParamsDict + from airflow.models.taskinstance import SimpleTaskInstance + from airflow.serialization.serialized_objects import SerializedBaseOperator, SerializedDAG + from airflow.utils.context import Context + + context_copy: dict[str, Any] = {} Review Comment: If it's only for fixing a mypy issue - you could add the type hint when you assigning `context_copy` below (L183) ########## airflow/utils/python_virtualenv.py: ########## @@ -149,3 +157,74 @@ def write_python_script( ) template = template_env.get_template("python_virtualenv_script.jinja2") template.stream(**jinja_context).dump(filename) + + +def context_to_json(context: Context) -> str: + from airflow.models.param import ParamsDict + from airflow.models.taskinstance import SimpleTaskInstance + from airflow.serialization.serialized_objects import SerializedBaseOperator, SerializedDAG + from airflow.utils.context import Context + + context_copy: dict[str, Any] = {} + + deprecated: set[str] = set(Context._DEPRECATION_REPLACEMENTS) # type: ignore[attr-defined] + exclude = { + "conf", + "conn", + "inlets", + "inlet_events", + "macros", + "outlets", + "outlet_events", + "triggering_dataset_events", + "var", Review Comment: Why are these values excluded? (might worth adding a comment) ########## airflow/operators/python.py: ########## @@ -440,6 +440,7 @@ def __init__( expect_airflow: bool = True, skip_on_exit_code: int | Container[int] | None = None, use_dill: bool = False, + use_airflow_context: bool = False, Review Comment: I'd be happy for a related docstring in `PythonVirtualenvOperator` and some more documentation in `docs/apache-airflow/howto/operator/python.rst` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org