mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
[multi-db] Fixed bug in request isolation of ConnectionInfoDescriptor.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3390 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c705f3a573
commit
b8cc6302a6
@ -270,6 +270,7 @@ def model_connection_name(klass):
|
|||||||
# No named connection for this model; use the default
|
# No named connection for this model; use the default
|
||||||
return _default
|
return _default
|
||||||
|
|
||||||
|
|
||||||
class ConnectionInfoDescriptor(object):
|
class ConnectionInfoDescriptor(object):
|
||||||
"""Descriptor used to access database connection information from a
|
"""Descriptor used to access database connection information from a
|
||||||
manager or other connection holder. Keeps a thread-local cache of
|
manager or other connection holder. Keeps a thread-local cache of
|
||||||
@ -283,6 +284,7 @@ class ConnectionInfoDescriptor(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cnx = local()
|
self.cnx = local()
|
||||||
self.cnx.cache = {}
|
self.cnx.cache = {}
|
||||||
|
dispatcher.connect(self.reset, signal=signals.request_finished)
|
||||||
|
|
||||||
def __get__(self, instance, type=None):
|
def __get__(self, instance, type=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
@ -291,9 +293,6 @@ class ConnectionInfoDescriptor(object):
|
|||||||
instance_connection = self.cnx.cache.get(instance, None)
|
instance_connection = self.cnx.cache.get(instance, None)
|
||||||
if instance_connection is None:
|
if instance_connection is None:
|
||||||
instance_connection = self.get_connection(instance)
|
instance_connection = self.get_connection(instance)
|
||||||
def reset():
|
|
||||||
self.reset(instance)
|
|
||||||
dispatcher.connect(reset, signal=signals.request_finished)
|
|
||||||
self.cnx.cache[instance] = instance_connection
|
self.cnx.cache[instance] = instance_connection
|
||||||
return instance_connection
|
return instance_connection
|
||||||
|
|
||||||
@ -306,8 +305,8 @@ class ConnectionInfoDescriptor(object):
|
|||||||
def get_connection(self, instance):
|
def get_connection(self, instance):
|
||||||
return connections[model_connection_name(instance.model)]
|
return connections[model_connection_name(instance.model)]
|
||||||
|
|
||||||
def reset(self, instance):
|
def reset(self):
|
||||||
self.cnx.cache[instance] = None
|
self.cnx.cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user