Skip to content

Commit bb7f6a7

Browse files
authored
fix: use packaging version parser instead of string splitting (#513)
🦕 Pair program with @tswast , @thejaredchapman , @aribray
1 parent 0f6be67 commit bb7f6a7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ def readme():
8585
"google-auth>=1.25.0,<3.0.0dev", # Work around pip wack.
8686
"google-cloud-bigquery>=2.25.2,<4.0.0dev",
8787
"google-cloud-bigquery-storage>=2.0.0,<3.0.0dev",
88+
"packaging",
8889
"pyarrow>=3.0.0",
89-
"sqlalchemy>=1.2.0",
90+
"sqlalchemy>=1.2.0,<2.0.0dev",
9091
"future",
9192
],
9293
extras_require=extras,

sqlalchemy_bigquery/base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from google.cloud.bigquery import dbapi
3333
from google.cloud.bigquery.table import TableReference
3434
from google.api_core.exceptions import NotFound
35-
35+
import packaging.version
3636
import sqlalchemy
3737
import sqlalchemy.sql.expression
3838
import sqlalchemy.sql.functions
@@ -340,14 +340,18 @@ def group_by_clause(self, select, **kw):
340340
# no way to tell sqlalchemy that, so it works harder than
341341
# necessary and makes us do the same.
342342

343-
__sqlalchemy_version_info = tuple(map(int, sqlalchemy.__version__.split(".")))
343+
__sqlalchemy_version_info = packaging.version.parse(sqlalchemy.__version__)
344344

345345
__expanding_text = (
346-
"EXPANDING" if __sqlalchemy_version_info < (1, 4) else "POSTCOMPILE"
346+
"EXPANDING"
347+
if __sqlalchemy_version_info < packaging.version.parse("1.4")
348+
else "POSTCOMPILE"
347349
)
348350

349351
# https://github.com/sqlalchemy/sqlalchemy/commit/f79df12bd6d99b8f6f09d4bf07722638c4b4c159
350-
__expanding_conflict = "" if __sqlalchemy_version_info < (1, 4, 27) else "__"
352+
__expanding_conflict = (
353+
"" if __sqlalchemy_version_info < packaging.version.parse("1.4.27") else "__"
354+
)
351355

352356
__in_expanding_bind = _helpers.substitute_string_re_method(
353357
rf"""
@@ -529,7 +533,7 @@ def visit_bindparam(
529533

530534
if bindparam.expanding: # pragma: NO COVER
531535
assert_(self.__expanded_param(param), f"Unexpected param: {param}")
532-
if self.__sqlalchemy_version_info < (1, 4, 27):
536+
if self.__sqlalchemy_version_info < packaging.version.parse("1.4.27"):
533537
param = param.replace(")", f":{bq_type})")
534538

535539
else:

0 commit comments

Comments
 (0)