Skip to content

Commit 8a9d0c4

Browse files
authored
django: fix 'week' lookup (#380)
* django: fix 'week' lookup. Translates lookup type `week` into `isoweek`, when used in either of: * DatabaseOperations.date_extract_sql * DatabaseOperations.datetime_extract_sql in order to conform to Django's ISO 8601 week expectations. The generated SQL will thus be: SELECT EXTRACT(isoweek from DATE(dt.start_time) from db_functions intead of SELECT EXTRACT(week from DATE(dt.start_time) from db_functions Fixes #263
1 parent aabf0ab commit 8a9d0c4

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
116116
'timezones.tests.NewDatabaseTests.test_query_datetimes',
117117
# To be investigated: https://github.com/orijtech/spanner-orm/issues/135
118118
'admin_changelist.tests.ChangeListTests.test_multiuser_edit',
119-
# Spanner's EXTRACT() 'week' differs from Django:
120-
# https://github.com/orijtech/spanner-orm/issues/263
121-
'db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_func',
122-
'db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_week_func',
123-
'db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_week_func_boundaries',
124-
'db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_extract_func',
125-
'db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_extract_func_with_timezone',
126-
'db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_extract_week_func',
127-
'db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_extract_week_func_boundaries',
128119
# using NULL with + crashes: https://github.com/orijtech/spanner-orm/issues/201
129120
'annotations.tests.NonAggregateAnnotationTestCase.test_combined_annotation_commutative',
130121
# Spanner loses DecimalField precision due to conversion to float:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class DatabaseOperations(BaseDatabaseOperations):
3030
# EXTRACT() function.
3131
# https://cloud.google.com/spanner/docs/functions-and-operators#extract
3232
extract_names = {
33-
'week_day': 'dayofweek',
34-
'iso_week': 'isoweek',
3533
'iso_year': 'isoyear',
34+
'week': 'isoweek',
35+
'week_day': 'dayofweek',
3636
}
3737

3838
def max_name_length(self):

0 commit comments

Comments
 (0)