[Answer]-Set role to oracle database user on django orm

1👍

I’m not sure if there’s any option by default. But I think that you can achieve your goal with Django signal (hook).

https://docs.djangoproject.com/en/dev/ref/signals/#connection-created

connection_created signal is called after a new connection to database is successfully made. It gives you a connection object. So you can do something like:

from django.db.backends.signals import connection_created

def set_role(**kwargs):
    connection = kwargs.get("connection", None)
    if connection:
        cursor = connection.cursor()
        cursor.execute("SET ROLE R_HRP IDENTIFIED BY %s", "myp4ssw0rd")

connection_created.connect(set_role)

I don’t have oracle database and hadn’t tested that either, but it should point you the right direction.

Leave a comment