Fix iObjectCreatedEvent firing with temporary ID (#1362)#1993
Fix iObjectCreatedEvent firing with temporary ID (#1362)#1993bhardwajparth51 wants to merge 1 commit intoplone:mainfrom
Conversation
Move notify(ObjectCreatedEvent) inside add() so it fires after INameChooser assigns the final ID, not before. Fixes the bug where subscribers could not rely on event.object.id for ID-dependent logic such as setting sequential shortnames. Fixes: plone#1362
|
@bhardwajparth51 thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment: To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
|
@jenkins-plone-org please run jobs |
davisagli
left a comment
There was a problem hiding this comment.
I need to check whether this matches when the ObjectCreatedEvent is triggered in other places where items are created in Plone.
Problem
When content is created without an explicit
id,plone.restapigenerates a temporary one (e.g.document.2026-03-06.1234) and later renames it viaINameChooser.IObjectCreatedEventwas fired before that rename, so subscribers relying onevent.object.id— for example to set sequential shortnames — would receive the temporary ID, not the final one.Solution
Moved
notify(ObjectCreatedEvent(obj))insideutils.add(), afterINameChooserassigns the final ID but before_setObject(), preserving the correct Zope lifecycle order:notify_created=Falseparameter toadd()for backward compatibilitytus.pyTesting
Added
test_post_to_folder_object_created_event_has_final_idwhich capturesevent.object.idat event-fire time and asserts it matches the final ID returned by the server. Fails on the original code, passes after the fix.If your pull request closes an open issue, include the exact text below, immediately followed by the issue number. When your pull request gets merged, then that issue will close automatically.
Closes #1362
📚 Documentation preview 📚: https://plonerestapi--1993.org.readthedocs.build/