Skip to content

Commit

Permalink
Only ignore 'temporary' objects in the ObjectAddedEvent handler.
Browse files Browse the repository at this point in the history
If we ignore temporary objects always, we cannot add references when first creating an object, because that'll try and create a KeyReference too, while the object is still inside of the portal_factory tool. Ignoring the add event will avoid creating a transaction on GET, while creating an explicit KeyReference for references is only done when attempting to save the object being created through the portal_factory, leading to a commit or abort depending on other factors.

We can only test for this in the original event handler, because the event handler for IPersistent is also invoked even if we were to register a more 'specific' handler for OFS.interfaces.IZopeObject.
  • Loading branch information
mjpieters committed Dec 1, 2011
1 parent a343e03 commit d79447c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,9 @@ Changelog
1.0.2 - unreleased
------------------

- Only ignore 'temporary' objects in the ObjectAddedEvent event handler.
[mj]

1.0.1 - 2011-11-30
------------------

Expand Down
3 changes: 0 additions & 3 deletions five/intid/configure.zcml
Expand Up @@ -9,7 +9,4 @@
<!-- CMFCore directoryview exceptions -->
<include file="cmfdirectoryview.zcml" />

<!-- CMFPlone factorytool exceptions -->
<include file="portalfactory.zcml" />

</configure>
13 changes: 13 additions & 0 deletions five/intid/intid.py
Expand Up @@ -14,6 +14,14 @@
from zope.event import notify
from zope.interface import implements

try:
from Products.CMFCore.utils import getToolByName
except ImportError:
# If not present, returning None suffices
def getToolByName(*args, **kw):
return None


_marker = []

class IntIds(z3IntIds):
Expand Down Expand Up @@ -72,6 +80,11 @@ def addIntIdSubscriber(ob, event):
Registers the object added in all unique id utilities and fires
an event for the catalogs.
"""
factorytool = getToolByName(ob, 'portal_factory', None)
if factorytool is not None and factorytool.isTemporary(ob):
# Ignore objects marked as temporary in the CMFPlone portal_factory tool
return

utilities = tuple(getAllUtilitiesRegisteredFor(IIntIds))
if utilities: # assert that there are any utilites
key = None
Expand Down
12 changes: 0 additions & 12 deletions five/intid/portalfactory.zcml

This file was deleted.

14 changes: 0 additions & 14 deletions five/intid/unreferenceable.py
@@ -1,10 +1,8 @@
# Sometimes persistent classes are never meant to be persisted. The most
# common example are CMFCore directory views and filesystem objects.
# Register specific handlers that are no-ops to circumvent
from five.intid.keyreference import KeyReferenceToPersistent
from zope.interface import implements
from zope.keyreference.interfaces import IKeyReference, NotYet
from Products.CMFCore.utils import getToolByName


def addIntIdSubscriber(ob, event):
Expand Down Expand Up @@ -32,15 +30,3 @@ def __cmp__(self, other):
if self.key_type_id == other.key_type_id:
return cmp(self, other)
return cmp(self.key_type_id, other.key_type_id)


class NoTemporaryKeyReference(KeyReferenceToPersistent):
"""A keyreference that never accepts objects in the portal_factory"""
implements(IKeyReference)

def __init__(self, wrapped_obj):
factorytool = getToolByName(wrapped_obj, 'portal_factory', None)
if factorytool is not None:
if factorytool.isTemporary(wrapped_obj):
raise NotYet()
super(NoTemporaryKeyReference, self).__init__(wrapped_obj)

0 comments on commit d79447c

Please sign in to comment.