plone.restapi icon indicating copy to clipboard operation
plone.restapi copied to clipboard

Fix iObjectCreatedEvent firing with temporary ID (#1362)

Open bhardwajparth51 opened this issue 8 months ago • 4 comments

Problem

When content is created without an explicit id, plone.restapi generates a temporary one (e.g. document.2026-03-06.1234) and later renames it via INameChooser. IObjectCreatedEvent was fired before that rename, so subscribers relying on event.object.id — for example to set sequential shortnames — would receive the temporary ID, not the final one.

Solution

Moved notify(ObjectCreatedEvent(obj)) inside utils.add(), after INameChooser assigns the final ID but before _setObject(), preserving the correct Zope lifecycle order:

ObjectCreatedEvent → ObjectWillBeAddedEvent → ObjectAddedEvent → ContainerModifiedEvent
  • Added notify_created=False parameter to add() for backward compatibility
  • Applied the same fix to the TUS upload path in tus.py

Testing

Added test_post_to_folder_object_created_event_has_final_id which captures event.object.id at event-fire time and asserts it matches the final ID returned by the server. Fails on the original code, passes after the fix.


  • [x] I signed and returned the Plone Contributor Agreement, and received and accepted an invitation to join a team in the Plone GitHub organization.
  • [x] I verified there aren't any other open pull requests for the same change.
  • [x] I followed the guidelines in Contributing to Plone.
  • [x] I successfully ran code quality checks on my changes locally.
  • [x] I successfully ran tests on my changes locally.
  • [x] If needed, I added new tests for my changes.
  • [x] If needed, I added documentation for my changes.
  • [x] I included a change log entry in my commits.

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/

bhardwajparth51 avatar Mar 06 '26 11:03 bhardwajparth51

@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:

@jenkins-plone-org please run jobs

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!

mister-roboto avatar Mar 06 '26 11:03 mister-roboto

@jenkins-plone-org please run jobs

bhardwajparth51 avatar Mar 06 '26 12:03 bhardwajparth51

@jenkins-plone-org please run jobs

bhardwajparth51 avatar Mar 18 '26 09:03 bhardwajparth51

@jenkins-plone-org please run jobs

bhardwajparth51 avatar Mar 18 '26 14:03 bhardwajparth51