Modified postgresql backend

25 views
Skip to first unread message

Alexander Scherbatey

unread,
Jul 6, 2016, 10:27:41 AM7/6/16
to Django users
Hello,

I need to create my own modified backend based on postgresql database backend, which use my wrapper for psycopg2 driver.
I tried to simply subclass django.db.backends.postgresql.DatabaseWrapper and redefine DatabaseWrapper.Database class member, but faced the fact that inside the class the <module>.Database member is used (in get_new_connection and is_usable methods) instead of self.Database.

I think, this is bug, isn't it?
I simply copy-pasted those two methods into my subclass and added self. , however, I think, this should be fixed in the library:

Here is my db.backends.my_postgresql.base file content:

####################################################
from django.db.backends.postgresql_psycopg2.base import *
from db.drivers import my_psycopg2

class DatabaseWrapper(DatabaseWrapper):
    Database = my_psycopg2

    def get_new_connection(self, conn_params):
        connection = self.Database.connect(**conn_params) # here I added 'self.'
        ...

####################################################
--
Alexander

Tim Graham

unread,
Jul 6, 2016, 11:23:08 AM7/6/16
to Django users
Looks reasonable to me -- want to submit a pull request? Maybe "self." was lost in a refactoring. If you can find where that happened, it's always helpful.
Reply all
Reply to author
Forward
0 new messages