A new, major Python cx_Oracle driver release is available 
<https://cjones-oracle.medium.com/open-source-python-thin-driver-for-oracle-database-e82aac7ecf5a>
 
and it comes with a brand new name: *python-oracledb* 
<https://oracle.github.io/python-oracledb/>.  At run time, the module name 
of the package is now '*oracledb*'.

With the aid of a shim to map the name space back to cx_Oracle, we  
(Oracle) have run Django's tests successfully:

    import sys
    import oracledb
    oracledb.version = "8.3.0"
    sys.modules["cx_Oracle"] = oracledb
    import cx_Oracle

But the new name space could do with some love to add Django support so the 
shim isn't needed.  

The ideas below are from the developers who worked on the python-oracledb 
project and tested Django.

For background, python-oracledb is now a Thin driver by default - it 
connects directly to Oracle Database without always needing Oracle Client 
libraries.  A “Thick” mode can be optionally enabled by an application call 
to init_oracle_client(). This mode has similar functionality to cx_Oracle 
and supports Oracle Database features that extend the Python DB API.  To 
use this mode, the Oracle Client libraries such as from Oracle Instant 
Client must be installed separately - same as with cx_Oracle.

There are three main topics for python-oracledb support in Django.

*1. Supporting the new name space*

There are a couple of options:

1a. What about completely replacing cx_Oracle with python-oracledb 
(oracledb)? Python-oracledb is just a major release of cx_Oracle with a new 
name.  We have run Django tests.  The new driver is 'thin' by default so 
it's easier for almost everyone to use.

1b. Alternatively a configuration option needs to allow either cx_Oracle or 
python oracledb to be used.  Perhaps this could be done by creating 
separate sub-modules, one for each name space, inside 
django.db.backends.oracle? If so, then the ‘ENGINE’ values could be:

       django.db.backends.oracle.oracledb

or

       django.db.backends.oracle.cx_Oracle

*2. Letting users choose whether to use python-oracledb Thin or Thick modes*

The default in python-oracledb is Thin mode, which will suit almost all 
users.  But other people may want features available only in Thick mode.

Thick mode can only be enabled with an explicit call to init_oracle_client() 
before any connection is created.  Some users will need to pass a lib_dir 
argument to it.

Some options:

2a. It could be documented that users need to explicitly call 
init_oracle_client() in their own code.  This may be easiest.

2b. Or how about adding a new parameter, say ‘DRIVER_MODE’ or simply 
‘MODE’, in settings.dict to allow users to use the ‘Thick’ mode of 
python-oracledb?  Django would need to make a call to init_oracle_client() 
internally.  This would need to take an optional parameter to be passed as 
the lib_dir argument to init_oracle_client()

*3. Supporting some new connection parameters and using service names 
instead of SIDs*

One new feature of the python-oracledb driver are additional connect() 
keyword arguments like hostname, port, service_name, tcp_connect_timeout.  
(The makedsn() function is now deprecated in python-oracle because of this 
change.)  How can new parameters best be passed to python-oracledb?

It may also be time to modernize some existing connection code in Django 
for Oracle. For example, to more obviously connect using database 'service 
names' instead of SIDs (which were obsoleted decades ago).  We recommend 
using service names instead of SIDs so that various database properties 
like Oracle's Application Continuity feature can be enabled.

It would be nice if apps could do something like:

   DATABASES = {
       'default': {
           'ENGINE': 'django.db.backends.oracle',
           'USER': 'scott',
           'PASSWORD': 'XXXX',
           'OPTIONS': {
               'host': 'example.com',
               'port': 1521,
               'service_name': 'orclpdb',
               'tcp_connect_timeout': 10,
          },
       }
   }

We have tossed around various ideas about all these but know it's best to 
get Django community involvement early about the design.

Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0de59a35-4630-460d-984d-2ace3dac2f1an%40googlegroups.com.

Reply via email to