Skip to content

Commit 809cf70

Browse files
committed
django: fix BinaryField value set on existing rows
When setting values on existing rows, SchemaEditor.add_field() must pass values as parameters for Spanner to handle them correctly. fixes #388
1 parent da2da97 commit 809cf70

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

packages/django-google-spanner/django_spanner/features.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
263263
'schema.tests.SchemaTests.test_primary_key',
264264
# Spanner limitation: Cannot remove a column from the primary key.
265265
'schema.tests.SchemaTests.test_alter_int_pk_to_int_unique',
266-
# adding BinaryField sets wrong value on existing rows:
267-
# https://github.com/orijtech/django-spanner/issues/388
268-
'migrations.test_operations.OperationTests.test_add_binaryfield',
269266
# changing a not null constraint isn't allowed if it affects an index:
270267
# https://github.com/orijtech/django-spanner/issues/378
271268
'migrations.test_operations.OperationTests.test_alter_field_with_index',

packages/django-google-spanner/django_spanner/schema.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ def add_field(self, model, field):
128128
# defaults for this but Spanner doesn't support them.)
129129
effective_default = self.effective_default(field)
130130
if effective_default is not None:
131-
self.execute('UPDATE %(table)s SET %(column)s=%(value)r' % {
131+
self.execute('UPDATE %(table)s SET %(column)s=%%s' % {
132132
"table": self.quote_name(model._meta.db_table),
133133
"column": self.quote_name(field.column),
134-
"value": effective_default,
135-
})
134+
}, (effective_default,))
136135
# Spanner doesn't support adding NOT NULL columns to existing tables.
137136
if not field.null:
138137
self.execute(self.sql_alter_column % {

0 commit comments

Comments
 (0)