Repository navigation
Description
Body
There is a regression that needs investigation. One of our tests is failing only on Python 3.11
tests/operators/test_python.py::TestPythonVirtualenvOperator::test_airflow_context
This test is part of PlainAssert suite and it has been skipped so far but after #35160 the PlainAssert (having only that test) have been brought back to regular tests and it turned out that it fails for Python 3.11
The error is about dill serializing the context:
INFO airflow.utils.process_utils:process_utils.py:186 Output:
INFO airflow.utils.process_utils:process_utils.py:190 Traceback (most recent call last):
INFO airflow.utils.process_utils:process_utils.py:190 File "/tmp/venv-call7xpd4uip/script.py", line 17, in <module>
INFO airflow.utils.process_utils:process_utils.py:190 arg_dict = dill.load(file)
INFO airflow.utils.process_utils:process_utils.py:190 ^^^^^^^^^^^^^^^
INFO airflow.utils.process_utils:process_utils.py:190 File "/usr/local/lib/python3.11/site-packages/dill/_dill.py", line 270, in load
INFO airflow.utils.process_utils:process_utils.py:190 return Unpickler(file, ignore=ignore, **kwds).load()
INFO airflow.utils.process_utils:process_utils.py:190 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INFO airflow.utils.process_utils:process_utils.py:190 File "/usr/local/lib/python3.11/site-packages/dill/_dill.py", line 472, in load
INFO airflow.utils.process_utils:process_utils.py:190 obj = StockUnpickler.load(self)
INFO airflow.utils.process_utils:process_utils.py:190 ^^^^^^^^^^^^^^^^^^^^^^^^^
INFO airflow.utils.process_utils:process_utils.py:190 TypeError: code() argument 13 must be str, not int
ERROR airflow.models.taskinstance.TaskInstance:taskinstance.py:2612 Task failed with exception
And likely connected with similar issues reported by others.
The way how to reproduce it:
- Run
breeze --python 3.11 - In the test remove the
or PY311in
@pytest.mark.skipif(
os.environ.get("PYTEST_PLAIN_ASSERTS") != "true" or PY311,
reason="assertion rewriting breaks this test because dill will try to serialize "
...
)
def test_airflow_context(self):
- Run this command:
PYTEST_PLAIN_ASSERTS="true" pytest tests/operators/test_python.py::TestPythonVirtualenvOperator::test_airflow_context --assert=plain
(Note - for this test assert rewriting in Pytest must be disabled that's why we have the ENV variable and --assert=plain`.
Example failure: https://github.com/apache/airflow/actions/runs/6710410150/job/18236357337 (and you can see that Python 3.8 - 3.10 are all green, only Python 3.11 is affected).
Committer
- I acknowledge that I am a maintainer/committer of the Apache Airflow project.
Activity
potiuk commentedon Oct 31, 2023
cc: @jens-scheffler-bosch, @ashb @uranusjr @Taragolis @bolkedebruin -> this one needs someone who they know their ways around dill and serialization :). It's Python 3.11 only and we had already a weird issue that Pytest assert rewrite was breaking this tests for other Python versions so we run it as separate type with
--assert=plainand PYTEST_PLAIN_ASSERTS="true"...Rather arcane thing, but I believe context serialization is broken currently for
dilland Python 3.11potiuk commentedon Oct 31, 2023
Detected it while improving our test suite - I found out that we have not run the
PlainAsserttests for a while and well, of course it turned out that Python 3.11 has problem with themTaragolis commentedon Oct 31, 2023
Assumption 1
Maybe it happen because we use dill==0.3.1.1.1 which was released at Sep 28, 2019 and Python 3.11 was released Oct 24, 2022?
Ok, let's break dependencies, install dill==0.3.7 and have a look what is happen
Assumption 2
Hmm, in the new version I could clearly see the warnings about pendulum.
Let's try pendulum 3.0.0b1, for allow run Airflow with this version I switched to #34744
And with combination of
pendulum==3.0.0b1anddill=0.3.7the test is passIf return any of this packages back then test failed
potiuk commentedon Oct 31, 2023
Yes. It's very likely about old version and pendulum. Unfortunately beam is rather tightly pinning dill:
https://github.com/apache/beam/blob/16fee7505e35e402cc28a55384c81fef64ead254/sdks/python/setup.py#L265
And yes 0.3.7 is the first one that has 3.11 support.
bad news 0.3.7 does not solve it either :(
Taragolis commentedon Oct 31, 2023
Maybe it is a good time to think about old issue #7870
potiuk commentedon Oct 31, 2023
Yeah. Why not :)
NotYuki commentedon Nov 16, 2023
If you don't need Airflow context you can try to pass
system_site_packages=Falseto Operator as a workaround:4 remaining items
anhdungitvn commentedon Oct 24, 2024
pip uninstall dill pip install dill `` dill-0.3.9 solved my issue.joeltorby commentedon Nov 18, 2024
Experienced same issue. This saved my day!
python down to 3.10 due to dill error in >=3.11 (apache/airflow#35307)