sqlalchemy-spanner 1.20.0__tar.gz → 1.21.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/PKG-INFO +6 -5
  2. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/README.rst +1 -1
  3. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py +259 -100
  4. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/version.py +1 -1
  5. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/setup.py +4 -3
  6. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/PKG-INFO +6 -5
  7. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/requires.txt +2 -2
  8. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/tests/test_suite_14.py +8 -8
  9. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/tests/test_suite_20.py +23 -3
  10. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/LICENSE +0 -0
  11. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/__init__.py +0 -0
  12. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py +0 -0
  13. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/dml.py +0 -0
  14. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/provision.py +0 -0
  15. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/google/cloud/sqlalchemy_spanner/requirements.py +0 -0
  16. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/setup.cfg +0 -0
  17. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/SOURCES.txt +0 -0
  18. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/dependency_links.txt +0 -0
  19. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/entry_points.txt +0 -0
  20. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/not-zip-safe +0 -0
  21. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/sqlalchemy_spanner.egg-info/top_level.txt +0 -0
  22. {sqlalchemy_spanner-1.20.0 → sqlalchemy_spanner-1.21.0}/tests/test_suite_13.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlalchemy-spanner
3
- Version: 1.20.0
3
+ Version: 1.21.0
4
4
  Summary: SQLAlchemy dialect integrated into Cloud Spanner database
5
- Home-page: https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy
5
+ Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/sqlalchemy-spanner
6
6
  Author: Google LLC
7
7
  Author-email: googleapis-packages@google.com
8
8
  License: Apache 2.0
@@ -13,11 +13,12 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
16
17
  Requires-Python: >=3.10
17
18
  License-File: LICENSE
18
- Requires-Dist: sqlalchemy>=1.1.13
19
+ Requires-Dist: sqlalchemy<3.0.0,>=1.1.13
19
20
  Requires-Dist: google-cloud-spanner>=3.55.0
20
- Requires-Dist: alembic
21
+ Requires-Dist: alembic<2.0.0,>=1.0.0
21
22
  Provides-Extra: tracing
22
23
  Requires-Dist: opentelemetry-api>=1.1.0; extra == "tracing"
23
24
  Requires-Dist: opentelemetry-sdk>=1.1.0; extra == "tracing"
@@ -40,7 +41,7 @@ Spanner dialect for SQLAlchemy
40
41
  Spanner dialect for SQLAlchemy represents an interface API designed to
41
42
  make it possible to control Cloud Spanner databases with SQLAlchemy API.
42
43
  The dialect is built on top of `the Spanner DB
43
- API <https://github.com/googleapis/python-spanner/tree/master/google/cloud/spanner_dbapi>`__,
44
+ API <https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner/google/cloud/spanner_dbapi>`__,
44
45
  which is designed in accordance with
45
46
  `PEP-249 <https://www.python.org/dev/peps/pep-0249/>`__.
46
47
 
@@ -4,7 +4,7 @@ Spanner dialect for SQLAlchemy
4
4
  Spanner dialect for SQLAlchemy represents an interface API designed to
5
5
  make it possible to control Cloud Spanner databases with SQLAlchemy API.
6
6
  The dialect is built on top of `the Spanner DB
7
- API <https://github.com/googleapis/python-spanner/tree/master/google/cloud/spanner_dbapi>`__,
7
+ API <https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner/google/cloud/spanner_dbapi>`__,
8
8
  which is designed in accordance with
9
9
  `PEP-249 <https://www.python.org/dev/peps/pep-0249/>`__.
10
10
 
@@ -12,17 +12,10 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import base64
15
+ import collections.abc
15
16
  import re
16
17
 
17
18
  import sqlalchemy
18
- from alembic.ddl.base import (
19
- ColumnNullable,
20
- ColumnType,
21
- alter_column,
22
- alter_table,
23
- format_server_default,
24
- format_type,
25
- )
26
19
  from google.api_core.client_options import ClientOptions
27
20
  from google.auth.credentials import AnonymousCredentials
28
21
  from google.cloud.spanner_v1 import Client, TransactionOptions
@@ -45,12 +38,32 @@ from sqlalchemy.sql.compiler import (
45
38
  selectable,
46
39
  )
47
40
  from sqlalchemy.sql.default_comparator import operator_lookup
48
- from sqlalchemy.sql.operators import json_getitem_op
41
+ from sqlalchemy.sql.operators import json_getitem_op, json_path_getitem_op
49
42
 
50
43
  from google.cloud import spanner_dbapi
51
44
  from google.cloud.sqlalchemy_spanner import version as sqlalchemy_spanner_version
52
45
  from google.cloud.sqlalchemy_spanner._opentelemetry_tracing import trace_call
53
46
 
47
+ # Defensively decouple the Alembic import so the Spanner dialect does not
48
+ # hard-depend on Alembic at runtime. A database dialect does not inherently
49
+ # require a schema migration tool, and consumers using only SQLAlchemy Core
50
+ # or ORM (or managing DDL outside of Alembic) can still import and use the
51
+ # dialect even if Alembic is omitted or unavailable in the environment
52
+ # (see #18584).
53
+ try:
54
+ from alembic.ddl.base import (
55
+ ColumnNullable,
56
+ ColumnType,
57
+ alter_column,
58
+ alter_table,
59
+ format_server_default,
60
+ format_type,
61
+ )
62
+
63
+ HAS_ALEMBIC_INSTALLED = True
64
+ except ImportError:
65
+ HAS_ALEMBIC_INSTALLED = False
66
+
54
67
  USING_SQLACLCHEMY_20 = False
55
68
  if sqlalchemy.__version__.split(".")[0] == "2":
56
69
  USING_SQLACLCHEMY_20 = True
@@ -76,6 +89,96 @@ def reset_connection(dbapi_conn, connection_record, reset_state=None):
76
89
  OPERATORS[json_getitem_op] = operator_lookup["json_getitem_op"]
77
90
 
78
91
 
92
+ _SPANNER_STRING_ESCAPE_TABLE = str.maketrans(
93
+ {
94
+ "\\": "\\\\",
95
+ '"': '\\"',
96
+ "'": "\\'",
97
+ "\n": "\\n",
98
+ "\r": "\\r",
99
+ "\t": "\\t",
100
+ **{
101
+ chr(c): f"\\u{c:04x}"
102
+ for c in (*range(0x00, 0x20), 0x7F)
103
+ if chr(c) not in ("\n", "\r", "\t")
104
+ },
105
+ }
106
+ )
107
+
108
+
109
+ def _escape_json_path_key(key):
110
+ """Escape a JSON member key for use inside double-quoted GoogleSQL JSONPath.
111
+
112
+ GoogleSQL's JSONPath lexer (`kEscKeyLexerStandard`) consumes `\\[^"]` as a
113
+ two-character pair during tokenization, while `RemoveBackSlashFollowedByChar`
114
+ only unescapes `\\"`. Doubling backslashes only when immediately preceding
115
+ `"` or end-of-string preserves interior backslashes while preventing any
116
+ trailing or quote-adjacent backslash from unescaping a `"` delimiter.
117
+ """
118
+ s = str(key)
119
+ s = re.sub(r'(\\+)(?="|\Z)', r"\g<1>\g<1>", s)
120
+ return s.replace('"', '\\"')
121
+
122
+
123
+ def _escape_spanner_string_literal(value, dialect=None):
124
+ """Escape a string value as a double-quoted GoogleSQL string literal."""
125
+ escaped = str(value).translate(_SPANNER_STRING_ESCAPE_TABLE)
126
+ if dialect is not None and dialect.identifier_preparer._double_percents:
127
+ escaped = escaped.replace("%", "%%")
128
+ return f'"{escaped}"'
129
+
130
+
131
+ def _is_json_path_sequence(value):
132
+ """Return True if value is a sequence of JSON path steps (not str/bytes)."""
133
+ return not isinstance(value, (str, bytes, bytearray)) and isinstance(
134
+ value, collections.abc.Sequence
135
+ )
136
+
137
+
138
+ def _format_json_path_step(elem):
139
+ """Format a single JSONPath member key or integer array index step."""
140
+ if isinstance(elem, int) and not isinstance(elem, bool):
141
+ return "[%s]" % elem
142
+ return '."%s"' % _escape_json_path_key(elem)
143
+
144
+
145
+ class _FormatTypeMixin:
146
+ def _format_value(self, value):
147
+ if _is_json_path_sequence(value):
148
+ return "$%s" % "".join(_format_json_path_step(elem) for elem in value)
149
+ return "$%s" % _format_json_path_step(value)
150
+
151
+ def bind_processor(self, dialect):
152
+ super_proc = self.string_bind_processor(dialect)
153
+
154
+ def process(value):
155
+ if value is None:
156
+ return None
157
+ formatted = self._format_value(value)
158
+ if super_proc:
159
+ formatted = super_proc(formatted)
160
+ return formatted
161
+
162
+ return process
163
+
164
+ def literal_processor(self, dialect):
165
+ def process(value):
166
+ if value is None:
167
+ return "NULL"
168
+ formatted = self._format_value(value)
169
+ return _escape_spanner_string_literal(formatted, dialect)
170
+
171
+ return process
172
+
173
+
174
+ class SpannerJSONIndexType(_FormatTypeMixin, types.JSON.JSONIndexType):
175
+ """Format a JSON index for Spanner JSON_VALUE path."""
176
+
177
+
178
+ class SpannerJSONPathType(_FormatTypeMixin, types.JSON.JSONPathType):
179
+ """Format a JSON path sequence for Spanner JSON_VALUE path."""
180
+
181
+
79
182
  # PickleType that can be used with Spanner.
80
183
  # Binary values are automatically encoded/decoded to/from base64.
81
184
  # Usage:
@@ -228,6 +331,10 @@ class SpannerExecutionContext(DefaultExecutionContext):
228
331
  if request_tag:
229
332
  self.cursor.request_tag = request_tag
230
333
 
334
+ timeout = self.execution_options.get("timeout")
335
+ if timeout is not None:
336
+ self.cursor.timeout = timeout
337
+
231
338
  ignore_transaction_warnings = self.execution_options.get(
232
339
  "ignore_transaction_warnings"
233
340
  )
@@ -287,6 +394,34 @@ class SpannerSQLCompiler(SQLCompiler):
287
394
  self.tablealiases = {}
288
395
  super().__init__(*args, **kwargs)
289
396
 
397
+ def _ensure_where_clause(self, statement):
398
+ where_criteria = getattr(statement, "_where_criteria", None)
399
+ where_clause = getattr(statement, "whereclause", None)
400
+ has_where = bool(where_criteria) or (where_clause is not None)
401
+ if not has_where:
402
+ return statement.where(expression.literal_column("1=1"))
403
+ return statement
404
+
405
+ def visit_delete(self, delete_stmt, **kw):
406
+ """Compile a DELETE statement.
407
+
408
+ Cloud Spanner requires a WHERE clause for all DELETE statements.
409
+ For SQLAlchemy Core/ORM AST delete statements (e.g. sa.delete(table)),
410
+ automatically inject 'WHERE 1=1' if no WHERE criteria were supplied.
411
+ """
412
+ delete_stmt = self._ensure_where_clause(delete_stmt)
413
+ return super().visit_delete(delete_stmt, **kw)
414
+
415
+ def visit_update(self, update_stmt, **kw):
416
+ """Compile an UPDATE statement.
417
+
418
+ Cloud Spanner requires a WHERE clause for all UPDATE statements.
419
+ For SQLAlchemy Core/ORM AST update statements (e.g. sa.update(table)),
420
+ automatically inject 'WHERE 1=1' if no WHERE criteria were supplied.
421
+ """
422
+ update_stmt = self._ensure_where_clause(update_stmt)
423
+ return super().visit_update(update_stmt, **kw)
424
+
290
425
  def get_from_hint_text(self, _, text):
291
426
  """Return a hint text.
292
427
 
@@ -325,52 +460,47 @@ class SpannerSQLCompiler(SQLCompiler):
325
460
  binary.right._compiler_dispatch(self, **kw),
326
461
  )
327
462
 
328
- def _generate_generic_binary(self, binary, opstring, eager_grouping=False, **kw):
329
- """The method is overriden to process JSON data type cases."""
330
- _in_binary = kw.get("_in_binary", False)
331
-
332
- kw["_in_binary"] = True
463
+ def _json_value_binary(self, binary, eager_grouping=False, **kw):
464
+ """Build a parameterized or safely escaped JSON_VALUE() function call."""
465
+ left_text = self.process(binary.left, eager_grouping=eager_grouping, **kw)
466
+ right = binary.right
333
467
 
334
- if isinstance(opstring, str):
335
- text = (
336
- binary.left._compiler_dispatch(
337
- self, eager_grouping=eager_grouping, **kw
338
- )
339
- + opstring
340
- + binary.right._compiler_dispatch(
341
- self, eager_grouping=eager_grouping, **kw
468
+ if isinstance(right, elements.BindParameter):
469
+ if not isinstance(
470
+ right.type, (types.JSON.JSONIndexType, types.JSON.JSONPathType)
471
+ ):
472
+ right = right._clone(maintain_key=True)
473
+ right.type = (
474
+ SpannerJSONPathType()
475
+ if getattr(binary, "operator", None) is json_path_getitem_op
476
+ else SpannerJSONIndexType()
342
477
  )
343
- )
344
- if _in_binary and eager_grouping:
345
- text = "(%s)" % text
478
+ right_text = self.process(right, eager_grouping=eager_grouping, **kw)
479
+ elif isinstance(right, elements.ClauseElement):
480
+ right_text = self.process(right, eager_grouping=eager_grouping, **kw)
346
481
  else:
347
- # got JSON data
348
- right_value = getattr(
349
- binary.right, "value", None
350
- ) or binary.right._compiler_dispatch(
351
- self, eager_grouping=eager_grouping, **kw
482
+ raw_value = getattr(right, "value", right)
483
+ right_text = SpannerJSONIndexType().literal_processor(self.dialect)(
484
+ raw_value
352
485
  )
353
486
 
354
- text = (
355
- binary.left._compiler_dispatch(
356
- self, eager_grouping=eager_grouping, **kw
357
- )
358
- + """, "$."""
359
- + str(right_value)
360
- + '"'
487
+ return "JSON_VALUE(%s, %s)" % (left_text, right_text)
488
+
489
+ def _generate_generic_binary(self, binary, opstring, eager_grouping=False, **kw):
490
+ """The method is overriden to process JSON data type cases."""
491
+ if isinstance(opstring, str):
492
+ return super()._generate_generic_binary(
493
+ binary, opstring, eager_grouping=eager_grouping, **kw
361
494
  )
362
- text = "JSON_VALUE(%s)" % text
495
+ return self._json_value_binary(binary, eager_grouping=eager_grouping, **kw)
363
496
 
364
- return text
497
+ def visit_json_getitem_op_binary(self, binary, operator, **kw):
498
+ """Build a JSON_VALUE() function call for single-key JSON indexing."""
499
+ return self._json_value_binary(binary, **kw)
365
500
 
366
501
  def visit_json_path_getitem_op_binary(self, binary, operator, **kw):
367
502
  """Build a JSON_VALUE() function call."""
368
- expr = """JSON_VALUE(%s, "$.%s")"""
369
-
370
- return expr % (
371
- self.process(binary.left, **kw),
372
- self.process(binary.right, **kw),
373
- )
503
+ return self._json_value_binary(binary, **kw)
374
504
 
375
505
  def render_literal_value(self, value, type_):
376
506
  """Render the value of a bind parameter as a quoted literal.
@@ -391,8 +521,28 @@ class SpannerSQLCompiler(SQLCompiler):
391
521
  # (e.g. JSON)
392
522
  return self.process(elements.Null._instance())
393
523
 
394
- raw = ["\\", "'", '"', "\n", "\t", "\r"]
395
- if isinstance(value, str) and any(single in value for single in raw):
524
+ if isinstance(type_, (types.JSON.JSONIndexType, types.JSON.JSONPathType)):
525
+ processor = type_._cached_literal_processor(self.dialect)
526
+ if processor:
527
+ return processor(value)
528
+
529
+ raw = ("\\", "'", '"', "\n", "\t", "\r")
530
+ has_ctrl = isinstance(value, str) and any(
531
+ (ord(ch) < 0x20 and ch not in ("\n", "\t")) or ord(ch) == 0x7F
532
+ for ch in value
533
+ )
534
+ if isinstance(value, str) and (
535
+ has_ctrl or any(single in value for single in raw)
536
+ ):
537
+ if (
538
+ has_ctrl
539
+ or '"""' in value
540
+ or value.endswith('"')
541
+ or value.endswith("\\")
542
+ ):
543
+ return _escape_spanner_string_literal(value, self.dialect)
544
+ if self.dialect.identifier_preparer._double_percents:
545
+ value = value.replace("%", "%%")
396
546
  value = 'r"""{}"""'.format(value)
397
547
  return value
398
548
  else:
@@ -440,9 +590,9 @@ class SpannerSQLCompiler(SQLCompiler):
440
590
  for c in expression._select_iterables(
441
591
  filter(
442
592
  lambda col: (
443
- not col.dialect_options.get("spanner", {}).get(
444
- "exclude_from_returning", False
445
- )
593
+ not (getattr(col, "dialect_options", None) or {})
594
+ .get("spanner", {})
595
+ .get("exclude_from_returning", False)
446
596
  ),
447
597
  returning_cols,
448
598
  )
@@ -889,6 +1039,10 @@ class SpannerDialect(DefaultDialect):
889
1039
  execution_ctx_cls = SpannerExecutionContext
890
1040
  _json_serializer = JsonObject
891
1041
  _json_deserializer = JsonObject
1042
+ colspecs = {
1043
+ types.JSON.JSONIndexType: SpannerJSONIndexType,
1044
+ types.JSON.JSONPathType: SpannerJSONPathType,
1045
+ }
892
1046
 
893
1047
  @classmethod
894
1048
  def dbapi(cls):
@@ -1882,55 +2036,60 @@ LIMIT 1
1882
2036
  cursor.execute(statement)
1883
2037
 
1884
2038
 
1885
- # Alembic ALTER operation override
1886
- @compiles(ColumnNullable, "spanner+spanner")
1887
- def visit_column_nullable(
1888
- element: "ColumnNullable", compiler: "SpannerDDLCompiler", **kw
1889
- ) -> str:
1890
- return _format_alter_column(
1891
- compiler,
1892
- element.table_name,
1893
- element.schema,
1894
- element.column_name,
1895
- element.existing_type,
1896
- element.nullable,
1897
- element.existing_server_default,
1898
- )
1899
-
1900
-
1901
- # Alembic ALTER operation override
1902
- @compiles(ColumnType, "spanner+spanner")
1903
- def visit_column_type(
1904
- element: "ColumnType", compiler: "SpannerDDLCompiler", **kw
1905
- ) -> str:
1906
- return _format_alter_column(
1907
- compiler,
1908
- element.table_name,
1909
- element.schema,
1910
- element.column_name,
1911
- element.type_,
1912
- element.existing_nullable,
1913
- element.existing_server_default,
1914
- )
2039
+ # Cloud Spanner requires ALTER TABLE ... ALTER COLUMN statements to specify the
2040
+ # complete column definition (type, nullability, and default expression), whereas
2041
+ # Alembic's default DDL compiler emits partial clauses (e.g., only SET NOT NULL
2042
+ # or TYPE). Because the @compiles decorators reference Alembic's ColumnNullable
2043
+ # and ColumnType classes at module import time, we only register these overrides
2044
+ # when Alembic is available in the environment.
2045
+ if HAS_ALEMBIC_INSTALLED:
2046
+ # Alembic ALTER operation override
2047
+ @compiles(ColumnNullable, "spanner+spanner")
2048
+ def visit_column_nullable(
2049
+ element: "ColumnNullable", compiler: "SpannerDDLCompiler", **kw
2050
+ ) -> str:
2051
+ return _format_alter_column(
2052
+ compiler,
2053
+ element.table_name,
2054
+ element.schema,
2055
+ element.column_name,
2056
+ element.existing_type,
2057
+ element.nullable,
2058
+ element.existing_server_default,
2059
+ )
1915
2060
 
2061
+ # Alembic ALTER operation override
2062
+ @compiles(ColumnType, "spanner+spanner")
2063
+ def visit_column_type(
2064
+ element: "ColumnType", compiler: "SpannerDDLCompiler", **kw
2065
+ ) -> str:
2066
+ return _format_alter_column(
2067
+ compiler,
2068
+ element.table_name,
2069
+ element.schema,
2070
+ element.column_name,
2071
+ element.type_,
2072
+ element.existing_nullable,
2073
+ element.existing_server_default,
2074
+ )
1916
2075
 
1917
- def _format_alter_column(
1918
- compiler, table_name, schema, column_name, type_, nullable, server_default
1919
- ):
1920
- # Older versions of SQLAlchemy pass in a boolean to indicate whether there
1921
- # is an existing DEFAULT constraint, instead of the actual DEFAULT constraint
1922
- # expression. In those cases, we do not want to explicitly include the DEFAULT
1923
- # constraint in the expression that is generated here.
1924
- if isinstance(server_default, bool):
1925
- server_default = None
1926
- return "%s %s %s%s%s" % (
1927
- alter_table(compiler, table_name, schema),
1928
- alter_column(compiler, column_name),
1929
- format_type(compiler, type_),
1930
- "" if nullable else " NOT NULL",
1931
- (
1932
- ""
1933
- if server_default is None
1934
- else f" DEFAULT {format_server_default(compiler, server_default)}"
1935
- ),
1936
- )
2076
+ def _format_alter_column(
2077
+ compiler, table_name, schema, column_name, type_, nullable, server_default
2078
+ ):
2079
+ # Older versions of SQLAlchemy pass in a boolean to indicate whether there
2080
+ # is an existing DEFAULT constraint, instead of the actual DEFAULT constraint
2081
+ # expression. In those cases, we do not want to explicitly include the DEFAULT
2082
+ # constraint in the expression that is generated here.
2083
+ if isinstance(server_default, bool):
2084
+ server_default = None
2085
+ return "%s %s %s%s%s" % (
2086
+ alter_table(compiler, table_name, schema),
2087
+ alter_column(compiler, column_name),
2088
+ format_type(compiler, type_),
2089
+ "" if nullable else " NOT NULL",
2090
+ (
2091
+ ""
2092
+ if server_default is None
2093
+ else f" DEFAULT {format_server_default(compiler, server_default)}"
2094
+ ),
2095
+ )
@@ -4,4 +4,4 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://developers.google.com/open-source/licenses/bsd
6
6
 
7
- __version__ = "1.20.0"
7
+ __version__ = "1.21.0"
@@ -22,9 +22,9 @@ import setuptools
22
22
  name = "sqlalchemy-spanner"
23
23
  description = "SQLAlchemy dialect integrated into Cloud Spanner database"
24
24
  dependencies = [
25
- "sqlalchemy>=1.1.13",
25
+ "sqlalchemy>=1.1.13,<3.0.0",
26
26
  "google-cloud-spanner>=3.55.0",
27
- "alembic",
27
+ "alembic>=1.0.0,<2.0.0",
28
28
  ]
29
29
  extras = {
30
30
  "tracing": [
@@ -67,6 +67,7 @@ setuptools.setup(
67
67
  "Programming Language :: Python :: 3.12",
68
68
  "Programming Language :: Python :: 3.13",
69
69
  "Programming Language :: Python :: 3.14",
70
+ "Programming Language :: Python :: 3.15",
70
71
  ],
71
72
  description=description,
72
73
  long_description=readme,
@@ -79,7 +80,7 @@ setuptools.setup(
79
80
  extras_require=extras,
80
81
  name=name,
81
82
  packages=packages,
82
- url="https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy",
83
+ url="https://github.com/googleapis/google-cloud-python/tree/main/packages/sqlalchemy-spanner",
83
84
  version=version,
84
85
  include_package_data=True,
85
86
  zip_safe=False,
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlalchemy-spanner
3
- Version: 1.20.0
3
+ Version: 1.21.0
4
4
  Summary: SQLAlchemy dialect integrated into Cloud Spanner database
5
- Home-page: https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy
5
+ Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/sqlalchemy-spanner
6
6
  Author: Google LLC
7
7
  Author-email: googleapis-packages@google.com
8
8
  License: Apache 2.0
@@ -13,11 +13,12 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
16
17
  Requires-Python: >=3.10
17
18
  License-File: LICENSE
18
- Requires-Dist: sqlalchemy>=1.1.13
19
+ Requires-Dist: sqlalchemy<3.0.0,>=1.1.13
19
20
  Requires-Dist: google-cloud-spanner>=3.55.0
20
- Requires-Dist: alembic
21
+ Requires-Dist: alembic<2.0.0,>=1.0.0
21
22
  Provides-Extra: tracing
22
23
  Requires-Dist: opentelemetry-api>=1.1.0; extra == "tracing"
23
24
  Requires-Dist: opentelemetry-sdk>=1.1.0; extra == "tracing"
@@ -40,7 +41,7 @@ Spanner dialect for SQLAlchemy
40
41
  Spanner dialect for SQLAlchemy represents an interface API designed to
41
42
  make it possible to control Cloud Spanner databases with SQLAlchemy API.
42
43
  The dialect is built on top of `the Spanner DB
43
- API <https://github.com/googleapis/python-spanner/tree/master/google/cloud/spanner_dbapi>`__,
44
+ API <https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner/google/cloud/spanner_dbapi>`__,
44
45
  which is designed in accordance with
45
46
  `PEP-249 <https://www.python.org/dev/peps/pep-0249/>`__.
46
47
 
@@ -1,6 +1,6 @@
1
- sqlalchemy>=1.1.13
1
+ sqlalchemy<3.0.0,>=1.1.13
2
2
  google-cloud-spanner>=3.55.0
3
- alembic
3
+ alembic<2.0.0,>=1.0.0
4
4
 
5
5
  [tracing]
6
6
  opentelemetry-api>=1.1.0
@@ -25,9 +25,7 @@ from unittest import mock
25
25
  import pytest
26
26
  import sqlalchemy
27
27
  from google.api_core.datetime_helpers import DatetimeWithNanoseconds
28
- from google.cloud import spanner_dbapi
29
28
  from google.cloud.spanner_v1 import Client, RequestOptions
30
- from google.cloud.sqlalchemy_spanner import version as sqlalchemy_spanner_version
31
29
  from sqlalchemy import (
32
30
  FLOAT,
33
31
  Boolean,
@@ -206,6 +204,8 @@ from sqlalchemy.testing.suite.test_update_delete import (
206
204
  )
207
205
  from sqlalchemy.types import Integer, Numeric, Text
208
206
 
207
+ from google.cloud import spanner_dbapi
208
+ from google.cloud.sqlalchemy_spanner import version as sqlalchemy_spanner_version
209
209
  from tests._helpers import get_db_url, get_project
210
210
 
211
211
  config.test_schema = ""
@@ -1576,7 +1576,7 @@ class NumericTest(_NumericTest):
1576
1576
  return run
1577
1577
 
1578
1578
  @emits_warning(r".*does \*not\* support Decimal objects natively")
1579
- def test_render_literal_numeric(self, literal_round_trip):
1579
+ def test_render_literal_numeric(self, literal_round_trip_spanner):
1580
1580
  """
1581
1581
  SPANNER OVERRIDE:
1582
1582
 
@@ -1585,14 +1585,14 @@ class NumericTest(_NumericTest):
1585
1585
  following insertions will fail with `Row [] already exists".
1586
1586
  Overriding the test to avoid the same failure.
1587
1587
  """
1588
- literal_round_trip(
1588
+ literal_round_trip_spanner(
1589
1589
  Numeric(precision=8, scale=4),
1590
1590
  [decimal.Decimal("15.7563")],
1591
1591
  [decimal.Decimal("15.7563")],
1592
1592
  )
1593
1593
 
1594
1594
  @emits_warning(r".*does \*not\* support Decimal objects natively")
1595
- def test_render_literal_numeric_asfloat(self, literal_round_trip):
1595
+ def test_render_literal_numeric_asfloat(self, literal_round_trip_spanner):
1596
1596
  """
1597
1597
  SPANNER OVERRIDE:
1598
1598
 
@@ -1601,13 +1601,13 @@ class NumericTest(_NumericTest):
1601
1601
  following insertions will fail with `Row [] already exists".
1602
1602
  Overriding the test to avoid the same failure.
1603
1603
  """
1604
- literal_round_trip(
1604
+ literal_round_trip_spanner(
1605
1605
  Numeric(precision=8, scale=4, asdecimal=False),
1606
1606
  [decimal.Decimal("15.7563")],
1607
1607
  [15.7563],
1608
1608
  )
1609
1609
 
1610
- def test_render_literal_float(self, literal_round_trip):
1610
+ def test_render_literal_float(self, literal_round_trip_spanner):
1611
1611
  """
1612
1612
  SPANNER OVERRIDE:
1613
1613
 
@@ -1616,7 +1616,7 @@ class NumericTest(_NumericTest):
1616
1616
  following insertions will fail with `Row [] already exists".
1617
1617
  Overriding the test to avoid the same failure.
1618
1618
  """
1619
- literal_round_trip(
1619
+ literal_round_trip_spanner(
1620
1620
  Float(4),
1621
1621
  [decimal.Decimal("15.7563")],
1622
1622
  [15.7563],
@@ -78,7 +78,6 @@ from sqlalchemy.testing.suite.test_ddl import (
78
78
  LongNameBlowoutTest as _LongNameBlowoutTest,
79
79
  )
80
80
  from sqlalchemy.testing.suite.test_ddl import TableDDLTest as _TableDDLTest
81
- from sqlalchemy.testing.suite.test_deprecations import * # noqa: F401, F403
82
81
  from sqlalchemy.testing.suite.test_dialect import * # noqa: F401, F403
83
82
  from sqlalchemy.testing.suite.test_dialect import (
84
83
  DifficultParametersTest as _DifficultParametersTest,
@@ -225,6 +224,15 @@ from tests._helpers import (
225
224
  get_project,
226
225
  )
227
226
 
227
+ try:
228
+ # SQLAlchemy 2.1+ removed test_deprecations from sqlalchemy.testing.suite.
229
+ # Guard this import so the test suite remains compatible with both 2.0.x and 2.1+.
230
+ # Tell flake8 to ignore F401 (unused import) and F403 (wildcard import) since
231
+ # pytest discovers the imported SQLAlchemy compliance test classes at module scope.
232
+ from sqlalchemy.testing.suite.test_deprecations import * # noqa: F401, F403
233
+ except ModuleNotFoundError:
234
+ pass
235
+
228
236
  config.test_schema = ""
229
237
 
230
238
 
@@ -721,6 +729,7 @@ class ComponentReflectionTest(_ComponentReflectionTest):
721
729
  [
722
730
  types.Integer,
723
731
  types.Numeric,
732
+ types.Float,
724
733
  types.DateTime,
725
734
  types.Date,
726
735
  types.Time,
@@ -2916,6 +2925,10 @@ class HasTableTest(_HasTableTest):
2916
2925
  def test_has_table_schema(self):
2917
2926
  pass
2918
2927
 
2928
+ @pytest.mark.skip("Not supported by Cloud Spanner")
2929
+ def test_has_multi_table_schema(self):
2930
+ pass
2931
+
2919
2932
  @pytest.mark.skip("Not supported by Cloud Spanner")
2920
2933
  def test_has_table_cache(self):
2921
2934
  pass
@@ -3066,19 +3079,26 @@ class JSONTest(_JSONTest):
3066
3079
  pass
3067
3080
 
3068
3081
  @pytest.mark.skip(
3069
- "Spanner JSON_VALUE() always returns STRING,"
3082
+ "Spanner JSON_VALUE() always returns STRING, "
3070
3083
  "thus, this test case can't be executed."
3071
3084
  )
3072
3085
  def test_index_typed_comparison(self):
3073
3086
  pass
3074
3087
 
3075
3088
  @pytest.mark.skip(
3076
- "Spanner JSON_VALUE() always returns STRING,"
3089
+ "Spanner JSON_VALUE() always returns STRING, "
3077
3090
  "thus, this test case can't be executed."
3078
3091
  )
3079
3092
  def test_path_typed_comparison(self):
3080
3093
  pass
3081
3094
 
3095
+ @pytest.mark.skip(
3096
+ "Spanner JSON_VALUE() always returns STRING, "
3097
+ "thus, this test case can't be executed."
3098
+ )
3099
+ def test_index_cross_casts(self):
3100
+ pass
3101
+
3082
3102
  @pytest.mark.skip("Custom JSON de-/serializers are not supported.")
3083
3103
  def test_round_trip_custom_json(self):
3084
3104
  pass