Skip to content

[Python] Make cloud storage dependencies optional on import in gcsio and s3io - #40178

Merged
shunping merged 5 commits into
apache:masterfrom
shunping:fix-37445
Sep 18, 2026
Merged

shunping merged 5 commits into
apache:masterfrom
shunping:fix-37445

Conversation

@shunping

Copy link
Copy Markdown
Collaborator
  • gcsio.py: Guard google-cloud-storage imports behind a flag instead of failing at module import time when GCP extras are not installed. This allows GCSFileSystem to be imported and registered in FileSystem.get_all_subclasses(), deferring RuntimeError until GcsIO is instantiated without a client.

  • s3io.py: Explicitly import boto3 inside the try block so BOTO3_INSTALLED is set to False when boto3 is missing (previously from apache_beam.io.aws.clients.s3 import boto3_client succeeded even without boto3, so BOTO3_INSTALLED has no effect).

fixes #37445

@shunping

shunping commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

r: @Abacn
cc: @hjtran

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@shunping
shunping requested a review from Abacn September 18, 2026 15:09
@shunping

Copy link
Copy Markdown
Collaborator Author

I got a bunch of test failures. Looks like our test suites often use whether import apache_beam.io.gcp.gcsio can run successfully as the criteria of the present of gcs dependencies. For example:

import apache_beam.io.gcp.gcsio # pylint: disable=unused-import

Our change in this PR breaks these tests and we have to fix them.

@Abacn Abacn left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, LGTM

Looks like our test suites often use whether import apache_beam.io.gcp.gcsio can run successfully as the criteria of the present of gcs dependencies.

This is the only thing a bit worrying. Current approach (Beam 2.77.0) is fragile admittedly. Hopefully this pattern isn't taken by users downstream

@shunping
shunping merged commit 0e32466 into apache:master Sep 18, 2026
101 of 103 checks passed
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.

GCSFileSystem requires gcp extra at lookup time while S3FileSystem does not

2 participants