Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Bug: avoid caching MongoDataManager instances in mongo container to a…
Browse files Browse the repository at this point in the history
…void

multiple MongoDataManagers in the single transaction in multithreaded
environment. Cache IMongoDataManagerProvider instead.
  • Loading branch information
kedder committed Apr 19, 2012
1 parent 0fe1d90 commit 31b957f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/mongopersist/zope/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ def __init__(self, collection=None, database=None,

@property
def _m_jar(self):
if not hasattr(self, '_v_m_jar'):
if not hasattr(self, '_v_mdmp'):
# If the container is in a Mongo storage hierarchy, then getting
# the datamanager is easy, otherwise we do an adapter lookup.
if interfaces.IMongoDataManager.providedBy(self._p_jar):
self._v_m_jar = self._p_jar
else:
provider = zope.component.getUtility(
return self._p_jar

# cache result of expensive component lookup
self._v_mdmp = zope.component.getUtility(
interfaces.IMongoDataManagerProvider)
self._v_m_jar = provider.get()
return self._v_m_jar

return self._v_mdmp.get()

def get_collection(self):
db_name = self._m_database or self._m_jar.default_database
Expand Down

0 comments on commit 31b957f

Please sign in to comment.