Skip to content

Commit 4ee18d8

Browse files
committed
django: fix lookup crash with multiple target fields
fixes #421
1 parent 456e66e commit 4ee18d8

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def cast_param_to_float(self, compiler, connection):
122122
if isinstance(self.lhs.output_field, DecimalField):
123123
params[0] = float(params[0])
124124
# Cast remote field lookups that must be integer but come in as string.
125-
elif (hasattr(self.lhs.output_field, 'target_field') and
126-
self.lhs.output_field.target_field.rel_db_type(connection) == 'INT64' and
127-
isinstance(params[0], str)):
128-
params[0] = int(params[0])
125+
elif hasattr(self.lhs.output_field, 'get_path_info'):
126+
for i, field in enumerate(self.lhs.output_field.get_path_info()[-1].target_fields):
127+
if field.rel_db_type(connection) == 'INT64' and isinstance(params[i], str):
128+
params[i] = int(params[i])
129129
return sql, params
130130

131131

packages/django-google-spanner/django_test_apps.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ file_storage
3333
file_uploads
3434
fixtures
3535
fixtures_model_package
36+
foreign_object
3637
from_db_value
3738
get_earliest_or_latest
3839
get_object_or_404

0 commit comments

Comments
 (0)