Skip to content

Conversation

@amoghrajesh
Copy link
Contributor

Saw errors like this in one of the CI runs:

_ test_apply_version_suffix_to_non_provider_pyproject_tomls[distributions1-init_file_path1-.dev1+testversion34-.dev0] _
[gw2] linux -- Python 3.10.19 /home/runner/.local/share/uv/tools/apache-airflow-breeze/bin/python

distributions = ('airflow-core', '.')
init_file_path = PosixPath('/home/runner/work/airflow/airflow/airflow-core/src/airflow/__init__.py')
version_suffix = '.dev1+testversion34', floored_version_suffix = '.dev0'

    @pytest.mark.parametrize(
        ("distributions", "init_file_path", "version_suffix", "floored_version_suffix"),
        [
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, ".dev0", ".dev0"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, ".dev1+testversion34", ".dev0"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "rc2", "rc1"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "rc2.dev0+localversion35", "rc1.dev0"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "rc1", "rc1"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "a2", "a1"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "b1", "b1"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, "b1+testversion34", "b1"),
            (("airflow-core", "."), AIRFLOW_CORE_INIT_PY, ".post1", ".post1"),
            (("task-sdk",), TASK_SDK_INIT_PY, ".dev0", ".dev0"),
            (("task-sdk",), TASK_SDK_INIT_PY, "rc2", "rc1"),
            (("task-sdk",), TASK_SDK_INIT_PY, "rc13", "rc1"),
            (("task-sdk",), TASK_SDK_INIT_PY, "a1", "a1"),
            (("task-sdk",), TASK_SDK_INIT_PY, "b3", "b1"),
            (("task-sdk",), TASK_SDK_INIT_PY, ".post1", ".post1"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, ".dev0", ".dev0"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, "rc2", "rc1"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, "rc13", "rc1"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, "a1", "a1"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, "b3", "b1"),
            (("airflow-ctl",), AIRFLOWCTL_INIT_PY, ".post1", ".post1"),
        ],
    )
    def test_apply_version_suffix_to_non_provider_pyproject_tomls(
        distributions: tuple[str, ...], init_file_path: Path, version_suffix: str, floored_version_suffix: str
    ):
        """
        Test the apply_version_suffix function with different version suffixes for pyproject.toml of non-provider.
        """
        try:
            import tomllib
        except ImportError:
            import tomli as tomllib
        distribution_paths = [AIRFLOW_ROOT_PATH / distribution for distribution in distributions]
        original_pyproject_toml_paths = [path / "pyproject.toml" for path in distribution_paths]
        original_contents = [path.read_text() for path in original_pyproject_toml_paths]
        original_init_py = init_file_path.read_text()
>       with apply_version_suffix_to_non_provider_pyproject_tomls(
            version_suffix, init_file_path, original_pyproject_toml_paths
        ) as modified_pyproject_toml_paths:

/home/runner/work/airflow/airflow/dev/breeze/tests/test_packages.py:444: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.10.19/arm64/lib/python3.10/contextlib.py:135: in __enter__
    return next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

version_suffix = '.dev1+testversion34'
init_file_path = PosixPath('/home/runner/work/airflow/airflow/airflow-core/src/airflow/__init__.py')
pyproject_toml_paths = [PosixPath('/home/runner/work/airflow/airflow/airflow-core/pyproject.toml'), PosixPath('/home/runner/work/airflow/airflow/pyproject.toml')]

    @contextmanager
    def apply_version_suffix_to_non_provider_pyproject_tomls(
        version_suffix: str, init_file_path: Path, pyproject_toml_paths: list[Path]
    ) -> Generator[list[Path], None, None]:
        from packaging.version import Version
    
        original_version_search = re.search('__version__ = "([^"]+)"', init_file_path.read_text())
        # Search beta version
        beta_version_search = re.search('__version__ = "([^"]+)b[0-9]+"', init_file_path.read_text())
        if not original_version_search:
            raise RuntimeError(f"Could not find __version__ in {init_file_path}")
        original_distribution_version = original_version_search.group(1)
        packaging_version = Version(original_distribution_version)
        # Forgiving check for beta versions
        if not beta_version_search and packaging_version.base_version != str(packaging_version):
>           raise RuntimeError(
                f"The package version in {init_file_path} should be `simple version` "
                f"(no suffixes) and it is `{original_distribution_version}`."
            )
E           RuntimeError: The package version in /home/runner/work/airflow/airflow/airflow-core/src/airflow/__init__.py should be `simple version` (no suffixes) and it is `3.2.0.dev0`.

/home/runner/work/airflow/airflow/dev/breeze/src/airflow_breeze/utils/packages.py:1142: RuntimeError
=========================== short test summary info ============================

Upon investigating, it seems that this is because of a race condition occurring due to parallel run of tests using pytest xdist.

This is what happens:

  • First test case: Modifies version to 3.2.0.dev0
  • Next test case: Starts running in parallel or before test case 0 finishes cleanup
  • This test case reads the file and sees 3.2.0.dev0 instead of 3.2.0 and because the validation doesn't handle that, this fails.

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@amoghrajesh amoghrajesh self-assigned this Nov 23, 2025
@boring-cyborg boring-cyborg bot added area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch labels Nov 23, 2025
@amoghrajesh amoghrajesh merged commit 632bfe7 into apache:main Nov 23, 2025
121 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 23, 2025
…non_provider_pyproject_tomls due to xdist runs (#58593)

(cherry picked from commit 632bfe7)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
@github-actions
Copy link

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Nov 23, 2025
…non_provider_pyproject_tomls due to xdist runs (apache#58593)

(cherry picked from commit 632bfe7)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
potiuk pushed a commit that referenced this pull request Nov 23, 2025
…non_provider_pyproject_tomls due to xdist runs (#58593) (#58595)

(cherry picked from commit 632bfe7)

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

potiuk commented Nov 23, 2025

Nice! Gooooooood Catch !

AIRFLOWCTL_INIT_PY = AIRFLOW_ROOT_PATH / "airflow-ctl" / "src" / "airflowctl" / "__init__.py"


@pytest.fixture
Copy link
Member

@potiuk potiuk Nov 23, 2025

Choose a reason for hiding this comment

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

Wait. .... But would not that break things in the other direction?

I can imagine that two tests that expect those versions to be updated might also be broken by this - because fixture wll FIX the versions if the race condition happens?

I think we need to either have some lock for those changes or to avoid in-place modifications - maybe just mock the "read" method for the tests reading the version rather than modify the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, thanks for sharing that perspective too. If more tests expect this, it might fail somewhere else, let me take a stab at making. this portion better to avoid such issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, better fix here: #58608

ephraimbuddy pushed a commit that referenced this pull request Dec 3, 2025
…non_provider_pyproject_tomls due to xdist runs (#58593) (#58595)

(cherry picked from commit 632bfe7)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
Copilot AI pushed a commit to jason810496/airflow that referenced this pull request Dec 5, 2025
itayweb pushed a commit to itayweb/airflow that referenced this pull request Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants