Skip to content

Commit

Permalink
Refs #33517 -- Prevented __second lookup from returning fractional se…
Browse files Browse the repository at this point in the history
…conds on Oracle.
  • Loading branch information
Hisham-Pak authored Jan 23, 2024
1 parent f4c5973 commit bbfbf0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 0 additions & 6 deletions django/db/backends/oracle/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests."
"test_trunc_week_before_1000",
},
"Oracle extracts seconds including fractional seconds (#33517).": {
"db_functions.datetime.test_extract_trunc.DateFunctionTests."
"test_extract_second_func_no_fractional",
"db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests."
"test_extract_second_func_no_fractional",
},
"Oracle doesn't support bitwise XOR.": {
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor",
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_null",
Expand Down
9 changes: 9 additions & 0 deletions django/db/backends/oracle/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def datetime_cast_time_sql(self, sql, params, tzname):

def datetime_extract_sql(self, lookup_type, sql, params, tzname):
sql, params = self._convert_sql_to_tz(sql, params, tzname)
if lookup_type == "second":
# Truncate fractional seconds.
return f"FLOOR(EXTRACT(SECOND FROM {sql}))", params
return self.date_extract_sql(lookup_type, sql, params)

def datetime_trunc_sql(self, lookup_type, sql, params, tzname):
Expand All @@ -188,6 +191,12 @@ def datetime_trunc_sql(self, lookup_type, sql, params, tzname):
return f"CAST({sql} AS DATE)", params
return f"TRUNC({sql}, %s)", (*params, trunc_param)

def time_extract_sql(self, lookup_type, sql, params):
if lookup_type == "second":
# Truncate fractional seconds.
return f"FLOOR(EXTRACT(SECOND FROM {sql}))", params
return self.date_extract_sql(lookup_type, sql, params)

def time_trunc_sql(self, lookup_type, sql, params, tzname=None):
# The implementation is similar to `datetime_trunc_sql` as both
# `DateTimeField` and `TimeField` are stored as TIMESTAMP where
Expand Down

0 comments on commit bbfbf0a

Please sign in to comment.