Opened 4 months ago

Closed 31 hours ago

#29057 closed Cleanup/optimization (fixed)

contrib.postgres OID caching crashes when initializing a ConnectionHandler manually

Reported by: Riccardo Di Virgilio Owned by: nobody
Component: contrib.postgres Version: 2.0
Severity: Normal Keywords:
Cc: felixxm Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

please note that this works on django 1.10

c = ConnectionHandler( {'temp': {'NAME': 'template1', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'rdv', 'HOST': 'localhost', 'PORT': '5432', 'PASSWORD': '', 'OPTIONS': {}, 'READONLY': False, 'BACKUP': False, 'RESTORE': 'release', 'RESTORE_AUTO': True, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'TEST': {'CHARSET': None, 'COLLATION': None, 'NAME': None, 'MIRROR': None}}, 'default': {'NAME': 'rotostampa_db', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'rdv', 'HOST': 'localhost', 'PORT': '5432', 'PASSWORD': '', 'OPTIONS': {}, 'READONLY': False, 'BACKUP': False, 'RESTORE': 'release', 'RESTORE_AUTO': True, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'TIME_ZONE': None, 'TEST': {'CHARSET': None, 'COLLATION': None, 'NAME': None, 'MIRROR': None}}})

c['temp'].cursor()
 raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias)
django.db.utils.ConnectionDoesNotExist: The connection temp doesn't exist

Change History (5)

comment:1 Changed 4 months ago by Riccardo Di Virgilio

the problem is django.contrib.postgres.signals.
there is a registred signal that is trying to read from connections and obviously it fails because "temp" is not registred

def get_hstore_oids(connection_alias):
    """Return hstore and hstore array OIDs."""
    with connections[connection_alias]

comment:2 Changed 4 months ago by felixxm

Cc: felixxm added

comment:3 Changed 4 months ago by Tim Graham

Component: Database layer (models, ORM)contrib.postgres
Summary: unable to retrive connection from ConnectionHandler in django 2.0contrib.postgres OID caching crashes when initializing a ConnectionHandler manually
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

While ConnectionHandler isn't a public API, I suppose we could change the implementation of 86a18dc46aae3a4a6410e3f3d864fa0ec4e5b2cd to reallow your use case. Would you like to provide a patch?

comment:4 Changed 4 months ago by Riccardo Di Virgilio

I know is not a public API, but it was the only way for me to interact with external databases without changing settings dynamically...

I normally offer to provide a patch, but for this bug I don't think I should: I really don't know what this function that is connected to this signal is doing...

sorry about that.

comment:5 Changed 31 hours ago by Riccardo Di Virgilio

Resolution: fixed
Status: newclosed

This bug seems to be fixed on latest master. I'm able to use the connection handler to create a cursor and connect to a db.

thanks

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