shahar1 commented on code in PR #41039:
URL: https://github.com/apache/airflow/pull/41039#discussion_r1708689743


##########
airflow/utils/python_virtualenv_script.jinja2:
##########
@@ -64,6 +64,20 @@ with open(sys.argv[3], "r") as file:
     virtualenv_string_args = list(map(lambda x: x.strip(), list(file)))
 {% endif %}
 
+{% if use_airflow_context | default(false) -%}
+if len(sys.argv) > 5:
+    import json
+    from types import ModuleType
+
+    class _MockPython(ModuleType):
+        @staticmethod
+        def get_current_context():
+            with open(sys.argv[5]) as file:
+                return json.load(file)

Review Comment:
   It makes sense to me that if the context is required to be serialized by 
using `BaseSerialization.serialize()`, it will be de-serialized by 
`BaseSerialization.deserialize()` ,as @potiuk mentioned. Otherwise we might 
encounter weird stuff when accessing some attributes, for example - the dates 
in their serialized format as you showed.
   For that reason, I suggest that upon setting `use_airflow_context = True`, 
then `system_site_packages` must also be set to `True`  - otherwise, an error 
will be raised. If there's additional toll of performance issues - maybe we 
could soften it to a warning.
   I'd be happy if you could test it out and see if it works as expected.
   



-- 
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

Reply via email to