Opened 7 years ago

Closed 6 years 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: Mariusz Felisiak 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 by Riccardo Di Virgilio, 7 years ago

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 by Mariusz Felisiak, 7 years ago

Cc: Mariusz Felisiak added

comment:3 by Tim Graham, 7 years ago

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 by Riccardo Di Virgilio, 7 years ago

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 by Riccardo Di Virgilio, 6 years ago

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