Skip to content

Commit f0319b4

Browse files
committed
guard missing imports
1 parent 4036b36 commit f0319b4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

sdks/python/apache_beam/io/requestresponse.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from typing import TypeVar
3636
from typing import Union
3737

38-
import redis
3938
from google.api_core.exceptions import TooManyRequests
4039

4140
import apache_beam as beam
@@ -46,6 +45,11 @@
4645
from apache_beam.transforms.util import BatchElements
4746
from apache_beam.utils import retry
4847

48+
try:
49+
import redis
50+
except ImportError:
51+
redis = None
52+
4953
RequestT = TypeVar('RequestT')
5054
ResponseT = TypeVar('ResponseT')
5155

@@ -689,6 +693,10 @@ def __init__(
689693
self._kwargs = kwargs if kwargs else {}
690694
self._source_caller = None
691695

696+
if redis is None:
697+
raise ImportError('Failed to import redis. You can ensure it is '
698+
'installed by installing the redis beam extra')
699+
692700
def get_read(self):
693701
"""get_read returns a PTransform for reading from the cache."""
694702
ensure_coders_exist(self._request_coder)

sdks/python/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pip_pre = True
3333
# allow apps that support color to use it.
3434
passenv=TERM,CLOUDSDK_CONFIG,DOCKER_*,TESTCONTAINERS_*,TC_*,ALLOYDB_PASSWORD
3535
# Set [] options for pip installation of apache-beam tarball.
36-
extras = test,dataframe,tfrecord,yaml
36+
extras = test,dataframe,redis,tfrecord,yaml
3737
# Don't warn that these commands aren't installed.
3838
allowlist_externals =
3939
false

0 commit comments

Comments
 (0)