django 1.10 unable to find TNS listener after upgrading oracle to 21c

I have an old application that is running django 1.10 with an oracle XE 11g back end. We are trying to upgrade the XE to 21c.

The issue is that django cannot find the TNS listener even though it is there and running. sqlplus works correctly so there is no issue with the listener itself.

The django application and the XE database are both running on the same server so there is no networking issue.

The main change as far as I can tell between the 11g and 21c is that the newer oracle database has plugin databases and needs to be addressed via the easy connect naming mechanism. Is that supported by django 1.10?

Directly using cx_Oracle to connect to the database from python3 also works without throwing errors.

Any pointers appreciated.

Django supports easy connect, however Django 1.10 is not supported anymore, moreover it doesn’t support cx_Oracle 8.1 and higher which officially support Oracle 21c. I would recommend to bump your Django and cx_Oracle versions.

I have tried going to Django 2.2 and cx_Oracle 8.1. But that is running into a bunch of compatibility errors, particularly around djangorestframework.

I have the following django dependencies in my code:

cx-Oracle
Django
django-allauth
django-defender
django-angular
django-debug-toolbar
django-debug-toolbar-request-history
django-debug-toolbar-template-profiler
django-debug-toolbar-template-timings
djangorestframework
django-auth-ldap

How can I find out which is the most stable set of versions to use without having to try each version independently?

I tried installing with no specified version number on all of these, but that runs into issues with some (soon to be) deprecated features. I don’t remember which ones right now, but will update this when I recreate it.

–p

Finally found the issue:

I had a prod.py and a dev.py in settings, and since I was only invoking the prod.py I did not notice that dev.py still had the older, non PDB addressing in the DATABASES definition. Usually both these are identical. All changes I was testing with in prod were being silently being overridden.

Found the issue by putting print statements in

/home/raxak/.virtualenvs//lib/python3.6/site-packages/django/db/backends/oracle/base.py

just before the Database.connect(…) statement in get_new_connection(…) to see what it was trying to connect with.

The final DATABASES definition that worked was:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',                                   
        'NAME' : '127.0.0.1:1521/XEPDB1',
        'PORT' : '',
        'HOST' : '',
        'USER' : <username>,
        'PASSWORD' : <password>,
        'CONN_MAX_AGE' : None,
        'OPTIONS' : {
            'threaded' : True,
        }
    }