You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sjyangkevin (via GitHub)" <gi...@apache.org> on 2025/08/31 04:49:51 UTC
Re: [I] Airflow 3: cannot run a `PythonVirtualenvOperator` with `pendulum<3` [airflow]
sjyangkevin commented on issue #50752:
URL: https://github.com/apache/airflow/issues/50752#issuecomment-3239759176
It's been a while since the last update. I revisited the issue and attempted the following fixes, but get stuck in considering some tradeoffs.
Below is what I attempt to achieve:
1. Check if the pendulum version in the target virtual environment is the same as the airflow environment. I think we only need this when the version is mismatched (especially for <=2 and ~=3).
2. If the version is not the same (e.g., virtual environment has pendulum~=2 but airflow environment has pendulum~=3), the `pendulum.DateTime` objects need to be converted into a format that can be loaded by any of the serializers (i.e., pickle, dill, cloudpickle). It is because the class definition is different between the two major versions. If the serializer serializes a v3 object, it cannot be deserialized in the virtual environment when pendulum~=2.
3. the conversion need to be implemented in `_write_args`, because we need to convert the objects before those being parsed by the serializer.
4. In the virtual environment (i.e., the python code executed in the virtual environment). We might need to "deserialize" the objects based to its original data types, before those are used (in case).
5. When the execution complete, we need to convert that back to the "compatible" format before passing back to the airflow environment.
### Serialization/Deserialization
I first attempted to use the `serialize` and the `deserialize` methods in the `airflow.serialization.serde`. However, it could be challenging to pass the function definition into the Python template in the virtual environment through similar method as `self.get_python_source()`. (if airflow is installed, probably can be easier to implement).
I think we need to let the code running in the virtual environment to use the same serializer/deserializer as the ones used in the airflow environment. I also attempted to implement simple serializer/deserializer (e.g., like `dt.to_iso8601_string(...)` and `pendulum.parse(...)`). But we already have a serde, probably it is not necessary to implement another one?
Trying to see if there is a good way to reduce code duplication and ensure the consistency.
### Identify Pendulum version in virtual environment
In the external task operator, I see an implementation to identify the version of airflow. I think the same approach can be used for identifying the version of pendulum, since the virtual environment may already be created before `_write_args` in the `_execute_python_callable_in_subprocess`. The intention is to limit the impact of this change (if the pendulum version is the same, probably the change shouldn't impact that serialization).
https://github.com/apache/airflow/blob/a811a586a3ffa546af16fd2b75de410d9b132fc7/providers/standard/src/airflow/providers/standard/operators/python.py#L890-L899
I am not sure if I am overthinking into it. I feel that without considering the above we may introduce code that impact more than solving the issue. It make sense from the perspective of users, in virtual environment, they are able to specify any package and version, but could be a little tricky when those dependencies are also required in the airflow environment, and that data/objects are used in both places.
Would appreciate any feedback in terms of how to move forwards. Should we proceed with this approach? Or this can be simplified in some way. Thanks!
--
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-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org