Skip to content

Fix SecretCache import error in Python 3.14 with pytest-xdist#64525

Merged
amoghrajesh merged 1 commit intoapache:mainfrom
amoghrajesh:sdk-py314
Mar 31, 2026
Merged

Fix SecretCache import error in Python 3.14 with pytest-xdist#64525
amoghrajesh merged 1 commit intoapache:mainfrom
amoghrajesh:sdk-py314

Conversation

@amoghrajesh
Copy link
Copy Markdown
Contributor


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

We noticed this recently and couple more times, one example: https://github.com/apache/airflow/actions/runs/23764195368/job/69256787158

Error:

FAILED task-sdk/tests/task_sdk/execution_time/test_context_cache.py::TestVariableCacheIntegration::test_delete_variable_invalidates_cache - multiprocessing.managers.RemoteError: 
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/python/lib/python3.14/multiprocessing/managers.py", line 257, in serve_client
    request = recv()
  File "/usr/python/lib/python3.14/multiprocessing/connection.py", line 257, in recv
    return _ForkingPickler.loads(buf.getbuffer())
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/cache.py", line 24, in <module>
    from airflow.sdk.configuration import conf
ImportError: cannot import name 'conf' from 'airflow.sdk.configuration' (/opt/airflow/task-sdk/src/airflow/sdk/configuration.py)

Turns out that when running tests with pytest-xdist parallel execution for py 3.14, the multiprocessing manager subprocess fails to import the cache module due to a module-level timezone import that triggers conf initialization via __getattr__. In this specific subprocess context, the lazy module-level __getattr__ mechanism does not work too reliably.

I have a fix that moves the timezone import from module-level to method-level
within _CacheValue.__init__() and is_expired(). This ensures that -

  1. The cache module can be imported without triggering
    the conf import chain
  2. The timezone functionality still works when _CacheValue is actually
    instantiated
  3. No behavioral changes to the cache functionality
  4. Tests pass both serially and with pytest-xdist parallel execution

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@amoghrajesh amoghrajesh requested review from ashb and kaxil as code owners March 31, 2026 06:43
@amoghrajesh amoghrajesh self-assigned this Mar 31, 2026
Copy link
Copy Markdown
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base on the PR description, haven't it already been solved in #64501 ?

Copy link
Copy Markdown
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just double-checked the timezone module and it make sense to. use lazy import as timezone module also import the conf.

# We don't want to `import *` here to avoid the risk of making adding too much to Public python API
from airflow.sdk._shared.timezones.timezone import (
coerce_datetime,
convert_to_utc,
datetime,
initialize,
make_naive,
parse,
utc,
utcnow,
)
try:
from airflow.sdk.configuration import conf

@amoghrajesh
Copy link
Copy Markdown
Contributor Author

Yes it was transitively importing it

@amoghrajesh
Copy link
Copy Markdown
Contributor Author

Failing tests being fixed by: #64524

@amoghrajesh amoghrajesh merged commit bcf74de into apache:main Mar 31, 2026
105 of 110 checks passed
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Mar 31, 2026

Indeed. That one is also needed. Cherry-picking

@potiuk potiuk added this to the Airflow 3.2.0 milestone Mar 31, 2026
potiuk pushed a commit to potiuk/airflow that referenced this pull request Mar 31, 2026
…dist (apache#64525)

(cherry picked from commit bcf74de)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
potiuk pushed a commit to potiuk/airflow that referenced this pull request Mar 31, 2026
…dist (apache#64525)

(cherry picked from commit bcf74de)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Mar 31, 2026

Cherry-picked #64537

potiuk pushed a commit to potiuk/airflow that referenced this pull request Mar 31, 2026
…dist (apache#64525)

(cherry picked from commit bcf74de)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
potiuk added a commit that referenced this pull request Mar 31, 2026
…dist (#64525) (#64537)

(cherry picked from commit bcf74de)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
Subham-KRLX pushed a commit to Subham-KRLX/airflow that referenced this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants