Skip to content

Commit e658d5a

Browse files
committed
Remove checks for minimum BQ Storage version
Since this is now a required dependency, there should not be any more pip quirks that used to allow installing BQ Storage as an extra, but without always respecting its minimum version pin.
1 parent 560ccd6 commit e658d5a

File tree

9 files changed

+7
-168
lines changed

9 files changed

+7
-168
lines changed

google/cloud/bigquery/_helpers.py

-26
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
from google.cloud._helpers import _to_bytes
2929
import packaging.version
3030

31-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
32-
3331

3432
_RFC3339_MICROS_NO_ZULU = "%Y-%m-%dT%H:%M:%S.%f"
3533
_TIMEONLY_WO_MICROS = "%H:%M:%S"
@@ -41,7 +39,6 @@
4139
re.VERBOSE,
4240
)
4341

44-
_MIN_BQ_STORAGE_VERSION = packaging.version.Version("2.0.0")
4542
_BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION = packaging.version.Version("2.6.0")
4643

4744

@@ -75,29 +72,6 @@ def is_read_session_optional(self) -> bool:
7572
"""
7673
return self.installed_version >= _BQ_STORAGE_OPTIONAL_READ_SESSION_VERSION
7774

78-
def verify_version(self):
79-
"""Verify that a recent enough version of BigQuery Storage extra is
80-
installed.
81-
82-
The function assumes that google-cloud-bigquery-storage extra is
83-
installed, and should thus be used in places where this assumption
84-
holds.
85-
86-
Because `pip` can install an outdated version of this extra despite the
87-
constraints in `setup.py`, the calling code can use this helper to
88-
verify the version compatibility at runtime.
89-
90-
Raises:
91-
LegacyBigQueryStorageError:
92-
If the google-cloud-bigquery-storage package is outdated.
93-
"""
94-
if self.installed_version < _MIN_BQ_STORAGE_VERSION:
95-
msg = (
96-
"Dependency google-cloud-bigquery-storage is outdated, please upgrade "
97-
f"it to version >= 2.0.0 (version found: {self.installed_version})."
98-
)
99-
raise LegacyBigQueryStorageError(msg)
100-
10175

10276
BQ_STORAGE_VERSIONS = BQStorageVersions()
10377

google/cloud/bigquery/client.py

+2-17
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@
5353
from google.cloud.bigquery._helpers import _get_sub_prop
5454
from google.cloud.bigquery._helpers import _record_field_to_json
5555
from google.cloud.bigquery._helpers import _str_or_none
56-
from google.cloud.bigquery._helpers import BQ_STORAGE_VERSIONS
5756
from google.cloud.bigquery._helpers import _verify_job_config_type
5857
from google.cloud.bigquery._http import Connection
5958
from google.cloud.bigquery import _pandas_helpers
6059
from google.cloud.bigquery.dataset import Dataset
6160
from google.cloud.bigquery.dataset import DatasetListItem
6261
from google.cloud.bigquery.dataset import DatasetReference
6362
from google.cloud.bigquery.enums import AutoRowIDs
64-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
6563
from google.cloud.bigquery.opentelemetry_tracing import create_span
6664
from google.cloud.bigquery import job
6765
from google.cloud.bigquery.job import (
@@ -469,17 +467,10 @@ def _ensure_bqstorage_client(
469467
) -> Optional["google.cloud.bigquery_storage.BigQueryReadClient"]:
470468
"""Create a BigQuery Storage API client using this client's credentials.
471469
472-
If a client cannot be created due to an outdated dependency
473-
`google-cloud-bigquery-storage`, raise a warning and return ``None``.
474-
475-
If the `bqstorage_client` argument is not ``None``, still perform the version
476-
check and return the argument back to the caller if the check passes. If it
477-
fails, raise a warning and return ``None``.
478-
479470
Args:
480471
bqstorage_client:
481-
An existing BigQuery Storage client instance to check for version
482-
compatibility. If ``None``, a new instance is created and returned.
472+
An existing BigQuery Storage client instance. If ``None``, a new
473+
instance is created and returned.
483474
client_options:
484475
Custom options used with a new BigQuery Storage client instance if one
485476
is created.
@@ -492,12 +483,6 @@ def _ensure_bqstorage_client(
492483
"""
493484
from google.cloud import bigquery_storage
494485

495-
try:
496-
BQ_STORAGE_VERSIONS.verify_version()
497-
except LegacyBigQueryStorageError as exc:
498-
warnings.warn(str(exc))
499-
return None
500-
501486
if bqstorage_client is None:
502487
bqstorage_client = bigquery_storage.BigQueryReadClient(
503488
credentials=self._credentials,

google/cloud/bigquery/exceptions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ class BigQueryError(Exception):
1818

1919

2020
class LegacyBigQueryStorageError(BigQueryError):
21-
"""Raised when too old a version of BigQuery Storage extra is detected at runtime."""
21+
"""Raised when too old a version of BigQuery Storage extra is detected at runtime.
22+
23+
.. deprecated:: 2.2.0
24+
Not used anymore and will be removed in the future.
25+
"""

google/cloud/bigquery/table.py

-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import google.cloud._helpers
3939
from google.cloud.bigquery import _helpers
4040
from google.cloud.bigquery import _pandas_helpers
41-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
4241
from google.cloud.bigquery.schema import _build_schema_resource
4342
from google.cloud.bigquery.schema import _parse_schema_resource
4443
from google.cloud.bigquery.schema import _to_schema_fields
@@ -1552,12 +1551,6 @@ def _validate_bqstorage(self, bqstorage_client, create_bqstorage_client):
15521551
)
15531552
return False
15541553

1555-
try:
1556-
_helpers.BQ_STORAGE_VERSIONS.verify_version()
1557-
except LegacyBigQueryStorageError as exc:
1558-
warnings.warn(str(exc))
1559-
return False
1560-
15611554
return True
15621555

15631556
def _get_next_page_response(self):

tests/unit/test__helpers.py

-31
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,6 @@ def _object_under_test(self):
2626

2727
return _helpers.BQStorageVersions()
2828

29-
def _call_fut(self):
30-
from google.cloud.bigquery import _helpers
31-
32-
_helpers.BQ_STORAGE_VERSIONS._installed_version = None
33-
return _helpers.BQ_STORAGE_VERSIONS.verify_version()
34-
35-
def test_raises_no_error_w_recent_bqstorage(self):
36-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
37-
38-
with mock.patch("google.cloud.bigquery_storage.__version__", new="2.0.0"):
39-
try:
40-
self._call_fut()
41-
except LegacyBigQueryStorageError: # pragma: NO COVER
42-
self.fail("Legacy error raised with a non-legacy dependency version.")
43-
44-
def test_raises_error_w_legacy_bqstorage(self):
45-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
46-
47-
with mock.patch("google.cloud.bigquery_storage.__version__", new="1.9.9"):
48-
with self.assertRaises(LegacyBigQueryStorageError):
49-
self._call_fut()
50-
51-
def test_raises_error_w_unknown_bqstorage_version(self):
52-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
53-
54-
with mock.patch("google.cloud.bigquery_storage", autospec=True) as fake_module:
55-
del fake_module.__version__
56-
error_pattern = r"version found: 0.0.0"
57-
with self.assertRaisesRegex(LegacyBigQueryStorageError, error_pattern):
58-
self._call_fut()
59-
6029
def test_installed_version_returns_cached(self):
6130
versions = self._object_under_test()
6231
versions._installed_version = object()

tests/unit/test__pandas_helpers.py

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
from google.cloud import bigquery_storage
4444

45-
_helpers.BQ_STORAGE_VERSIONS.verify_version()
4645

4746
PANDAS_MINIUM_VERSION = pkg_resources.parse_version("1.0.0")
4847

tests/unit/test_client.py

-39
Original file line numberDiff line numberDiff line change
@@ -618,25 +618,6 @@ def test_ensure_bqstorage_client_creating_new_instance(self):
618618
client_info=mock.sentinel.client_info,
619619
)
620620

621-
def test_ensure_bqstorage_client_obsolete_dependency(self):
622-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
623-
624-
creds = _make_credentials()
625-
client = self._make_one(project=self.PROJECT, credentials=creds)
626-
627-
patcher = mock.patch(
628-
"google.cloud.bigquery.client.BQ_STORAGE_VERSIONS.verify_version",
629-
side_effect=LegacyBigQueryStorageError("BQ Storage too old"),
630-
)
631-
with patcher, warnings.catch_warnings(record=True) as warned:
632-
bqstorage_client = client._ensure_bqstorage_client()
633-
634-
self.assertIsNone(bqstorage_client)
635-
matching_warnings = [
636-
warning for warning in warned if "BQ Storage too old" in str(warning)
637-
]
638-
assert matching_warnings, "Obsolete dependency warning not raised."
639-
640621
def test_ensure_bqstorage_client_existing_client_check_passes(self):
641622
creds = _make_credentials()
642623
client = self._make_one(project=self.PROJECT, credentials=creds)
@@ -648,26 +629,6 @@ def test_ensure_bqstorage_client_existing_client_check_passes(self):
648629

649630
self.assertIs(bqstorage_client, mock_storage_client)
650631

651-
def test_ensure_bqstorage_client_existing_client_check_fails(self):
652-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
653-
654-
creds = _make_credentials()
655-
client = self._make_one(project=self.PROJECT, credentials=creds)
656-
mock_storage_client = mock.sentinel.mock_storage_client
657-
658-
patcher = mock.patch(
659-
"google.cloud.bigquery.client.BQ_STORAGE_VERSIONS.verify_version",
660-
side_effect=LegacyBigQueryStorageError("BQ Storage too old"),
661-
)
662-
with patcher, warnings.catch_warnings(record=True) as warned:
663-
bqstorage_client = client._ensure_bqstorage_client(mock_storage_client)
664-
665-
self.assertIsNone(bqstorage_client)
666-
matching_warnings = [
667-
warning for warning in warned if "BQ Storage too old" in str(warning)
668-
]
669-
assert matching_warnings, "Obsolete dependency warning not raised."
670-
671632
def test_create_routine_w_minimal_resource(self):
672633
from google.cloud.bigquery.routine import Routine
673634
from google.cloud.bigquery.routine import RoutineReference

tests/unit/test_magics.py

-25
Original file line numberDiff line numberDiff line change
@@ -322,31 +322,6 @@ def test__make_bqstorage_client_true():
322322
assert isinstance(got, bigquery_storage.BigQueryReadClient)
323323

324324

325-
def test__make_bqstorage_client_true_obsolete_dependency():
326-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
327-
328-
credentials_mock = mock.create_autospec(
329-
google.auth.credentials.Credentials, instance=True
330-
)
331-
test_client = bigquery.Client(
332-
project="test_project", credentials=credentials_mock, location="test_location"
333-
)
334-
335-
patcher = mock.patch(
336-
"google.cloud.bigquery.client.BQ_STORAGE_VERSIONS.verify_version",
337-
side_effect=LegacyBigQueryStorageError("BQ Storage too old"),
338-
)
339-
with patcher, warnings.catch_warnings(record=True) as warned:
340-
got = magics._make_bqstorage_client(test_client, True, {})
341-
342-
assert got is None
343-
344-
matching_warnings = [
345-
warning for warning in warned if "BQ Storage too old" in str(warning)
346-
]
347-
assert matching_warnings, "Obsolete dependency warning not raised."
348-
349-
350325
@pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
351326
def test__make_bqstorage_client_true_missing_gapic(missing_grpcio_lib):
352327
credentials_mock = mock.create_autospec(

tests/unit/test_table.py

-21
Original file line numberDiff line numberDiff line change
@@ -1844,27 +1844,6 @@ def test__validate_bqstorage_returns_false_when_completely_cached(self):
18441844
)
18451845
)
18461846

1847-
def test__validate_bqstorage_returns_false_w_warning_if_obsolete_version(self):
1848-
from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
1849-
1850-
iterator = self._make_one(first_page_response=None) # not cached
1851-
1852-
patcher = mock.patch(
1853-
"google.cloud.bigquery.table._helpers.BQ_STORAGE_VERSIONS.verify_version",
1854-
side_effect=LegacyBigQueryStorageError("BQ Storage too old"),
1855-
)
1856-
with patcher, warnings.catch_warnings(record=True) as warned:
1857-
result = iterator._validate_bqstorage(
1858-
bqstorage_client=None, create_bqstorage_client=True
1859-
)
1860-
1861-
self.assertFalse(result)
1862-
1863-
matching_warnings = [
1864-
warning for warning in warned if "BQ Storage too old" in str(warning)
1865-
]
1866-
assert matching_warnings, "Obsolete dependency warning not raised."
1867-
18681847
def test_to_arrow(self):
18691848
from google.cloud.bigquery.schema import SchemaField
18701849

0 commit comments

Comments
 (0)