New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix object creation events #549

Merged
merged 8 commits into from Jun 26, 2018

Conversation

Projects
None yet
4 participants
@buchi
Member

buchi commented Jun 23, 2018

This makes object creation in plone.restapi behave more like TTW object creation.

New objects are now created in the following way:

  1. Create an empty object
  2. Deserialize it
  3. Fire object created event
  4. Add object to container
  5. Fire object added and container modified events

Before that change new objects were created in the this way:

  1. Create an empty object
  2. Fire object created event
  3. Add object to container
  4. Fire object added and container modified events
  5. Deserialize object
  6. Fire modified event
@coveralls

This comment has been minimized.

coveralls commented Jun 23, 2018

Coverage Status

Coverage decreased (-0.9%) to 96.523% when pulling b612cb3 on fix-object-creation-events into 2c1f9f6 on master.

@davisagli

Nice job pulling out the right pieces from CMFCore to make this happen. It mostly looks good, but I made one small suggestion.

id_ = obj.getId()
# Archetypes objects are already created in a container thus we just fire
# the notification events.
if container == aq_parent(obj):

This comment has been minimized.

@davisagli

davisagli Jun 24, 2018

Member

Comparing acquisition-wrapped objects with == can be problematic (two different wrappers of the same object are not equal). Probably best to do if aq_base(container) is aq_base(aq_parent(obj))

And maybe we should raise an exception if obj already has a different parent?

This comment has been minimized.

@buchi

buchi Jun 24, 2018

Member

Thanks, I've amended that.

Not sure, how a different parent would be possible at all? Have you something in mind how this could happen?

@tisto

This comment has been minimized.

Member

tisto commented Jun 24, 2018

@buchi this is at least a possible breaking change, correct?

@buchi

This comment has been minimized.

Member

buchi commented Jun 24, 2018

@tisto It shouldn't break anything unless you're heavily relying on plone.restapi internals, e.g. customizing the endpoint for adding objects.

@tisto tisto added this to the 3.0.0 milestone Jun 24, 2018

@buchi

This comment has been minimized.

Member

buchi commented Jun 25, 2018

@tisto Turns out this can break custom content deserializers. I've added a note to the changelog.

@tisto

This comment has been minimized.

Member

tisto commented Jun 25, 2018

@buchi thank you! Would you mind adding that section to our upgrade guide as well?

Issue has been solved.

@tisto tisto self-requested a review Jun 25, 2018

@tisto

tisto approved these changes Jun 25, 2018

else:
rval = container._setObject(id_, obj)
new_id = isinstance(rval, basestring) and rval or id_
return container._getOb(new_id)

This comment has been minimized.

@davisagli

davisagli Jun 25, 2018

Member

_setObject triggers ObjectAddedEvent which can end up triggering a content rule to move the item to a different container. In this case we might need the same workaround that we use in plone.dexterity.utils.addContentToContainer to work around this edge case:

try:
    return container._getOb(newName)
except AttributeError:
    uuid = IUUID(object)
    return uuidToObject(uuid)

This comment has been minimized.

@buchi

buchi Jun 26, 2018

Member

I've added that.

buchi added some commits Jun 23, 2018

Add create flag to deserializers
Setting `create=True` indicates the creation of a new object and prevents
firing modified events.
Fix object creation events
Change object creation and deserialization order:
1. Create an empty object
2. Deserialize it
3. Fire object created event
4. Add object to container
5. Fire object added and container modified events
Temporarily acquisition wrap created objects
Fixes vocabularies depending on tools in deserialization.
@buchi

This comment has been minimized.

Member

buchi commented Jun 26, 2018

@tisto added small section in the upgrade guide.

@tisto

This comment has been minimized.

Member

tisto commented Jun 26, 2018

@buchi awesome. Thank you!
@davisagli would you mind having another look and approving the merge?

@tisto tisto merged commit d43ef89 into master Jun 26, 2018

4 checks passed

code-quality/landscape Landscape has completed the code quality check
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.3%) to 96.127%
Details

@tisto tisto deleted the fix-object-creation-events branch Jun 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment