Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#36675 closed Bug (duplicate)

Oracle dialect depends on implementation detail which was changed in python-oracledb 3.4

Reported by: Anthony Tuininga Owned by: Varun Kasyap Pentamaraju
Component: Database layer (models, ORM) Version: 5.2
Severity: Normal Keywords: oracle
Cc: Anthony Tuininga Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

This issue was reported by a Django user with the upgrade to python-oracledb 3.4: https://github.com/oracle/python-oracledb/issues/544. The issue is that the Django Oracle dialect depended on an implementation detail which changed in python-oracledb 3.4.

The following patch addresses that and is fine for all supported versions of cx_Oracle and python-oracledb:

diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 3b37c38f97..71089c1166 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -438,7 +438,7 @@ class OracleParam:
                 param = 0
         if hasattr(param, "bind_parameter"):
             self.force_bytes = param.bind_parameter(cursor)
-        elif isinstance(param, (Database.Binary, datetime.timedelta)):
+        elif isinstance(param, (bytes, datetime.timedelta)):
             self.force_bytes = param
         else:
             # To transmit to the database, we need Unicode if supported

Change History (5)

in reply to:  description comment:1 by Anthony Tuininga, 3 weeks ago

A more comprehensive patch (also safe for all supported versions of cx_Oracle and python-oracledb):

diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 3b37c38f97..71089c1166 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -438,7 +438,7 @@ class OracleParam:
                 param = 0
         if hasattr(param, "bind_parameter"):
             self.force_bytes = param.bind_parameter(cursor)
-        elif isinstance(param, (Database.Binary, datetime.timedelta)):
+        elif isinstance(param, (bytes, datetime.timedelta)):
             self.force_bytes = param
         else:
             # To transmit to the database, we need Unicode if supported
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index 59eecdba20..14c69a59ff 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -273,12 +273,12 @@ END;
         return value
 
     def convert_datefield_value(self, value, expression, connection):
-        if isinstance(value, Database.Timestamp):
+        if isinstance(value, datetime.datetime):
             value = value.date()
         return value
 
     def convert_timefield_value(self, value, expression, connection):
-        if isinstance(value, Database.Timestamp):
+        if isinstance(value, datetime.datetime):
             value = value.time()
         return value
 
diff --git a/django/db/backends/oracle/utils.py b/django/db/backends/oracle/utils.py
index 57d97b3f77..d69414240c 100644
--- a/django/db/backends/oracle/utils.py
+++ b/django/db/backends/oracle/utils.py
@@ -24,7 +24,7 @@ class InsertVar:
         "BooleanField": int,
         "FloatField": Database.DB_TYPE_BINARY_DOUBLE,
         "DateTimeField": Database.DB_TYPE_TIMESTAMP,
-        "DateField": Database.Date,
+        "DateField": datetime.date,
         "DecimalField": decimal.Decimal,
     }

comment:2 by Varun Kasyap Pentamaraju, 3 weeks ago

Owner: set to Varun Kasyap Pentamaraju
Status: newassigned

comment:3 by Varun Kasyap Pentamaraju, 3 weeks ago

I've examined the code in the stable/5.2.x branch and found that all three changes mentioned in the ticket are already implemented:

  1. In django/db/backends/oracle/base.py: Already using bytes instead of Database.Binary
  2. In django/db/backends/oracle/operations.py: Already using datetime.datetime instead of Database.Timestamp
  3. In django/db/backends/oracle/utils.py: Already using datetime.date instead of Database.Date

Could you please advise if there are other aspects of this ticket that still need to be addressed, or if it can be closed as already fixed?

comment:4 by Mariusz Felisiak, 3 weeks ago

Resolution: duplicate
Status: assignedclosed

We don't intend to fix this in Django 5.1 or 4.2, both versions already document lack of support for oracledb >= 3.4.0. Duplicate of #36646.

comment:5 by Natalia Bidart, 3 weeks ago

Hello, thank you for your ticket report! This is a dupe of #36646 which is already fixed and will be released with the next 5.2.8 release.

Note: See TracTickets for help on using tickets.
Back to Top