Skip to content

Conversation

@NayanMathur411
Copy link
Contributor

@NayanMathur411 NayanMathur411 commented Jan 20, 2026

Fixes #35717

When using --requirements_file, the Python SDK downloads wheel packages to a cache directory (TEMPDIR/dataflow-requirements-cache), the stager would stage all packages in the cache directory, even those not needed by the current workflow. This caused unnecessary files to be staged and uploaded.

(cc @hjtran)

Changes

  • Modified _populate_requirements_cache to download packages to a temporary directory first, then copy to cache. This allows tracking exactly which packages are needed for the current requirements file.
  • Updated create_job_resources to only stage packages returned by _populate_requirements_cache, rather than globbing the entire cache directory.
  • Renamed cache directory from dataflow-requirements-cache to beam-requirements-cache (runner-agnostic naming).
  • Added test test_only_required_packages_staged_from_cache to verify the fix.

Example

Before this fix:

  1. Run pipeline A with requirements.txt containing numpy, pandas → cache has numpy.whl, pandas.whl
  2. Run pipeline B with requirements.txt containing scipy → cache now has numpy.whl, pandas.whl, scipy.whl
  3. Pipeline B stages all 3 packages, even though only scipy is needed

After this fix:

  • Workflow B only stages scipy.whl

Testing

  • Existing stager_test.py tests pass
  • New test test_only_required_packages_staged_from_cache verifies only required packages are staged

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@NayanMathur411 NayanMathur411 changed the title Fix cached wheels used in future runs Only stage required wheel packages from requirements cache, not entire cache directory Jan 20, 2026
@github-actions
Copy link
Contributor

Assigning reviewers:

R: @damccorm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Python] Python cache directory leaks cached packages between pipeline runs

1 participant