Skip to content

Fix iObjectCreatedEvent firing with temporary ID (#1362)#1993

Open
bhardwajparth51 wants to merge 1 commit intoplone:mainfrom
bhardwajparth51:fix-iObjectCreateEvent
Open

Fix iObjectCreatedEvent firing with temporary ID (#1362)#1993
bhardwajparth51 wants to merge 1 commit intoplone:mainfrom
bhardwajparth51:fix-iObjectCreateEvent

Conversation

@bhardwajparth51
Copy link

@bhardwajparth51 bhardwajparth51 commented Mar 6, 2026

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.


  • I signed and returned the Plone Contributor Agreement, and received and accepted an invitation to join a team in the Plone GitHub organization.
  • I verified there aren't any other open pull requests for the same change.
  • I followed the guidelines in Contributing to Plone.
  • I successfully ran code quality checks on my changes locally.
  • I successfully ran tests on my changes locally.
  • If needed, I added new tests for my changes.
  • If needed, I added documentation for my changes.
  • 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/

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
@mister-roboto
Copy link

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

@bhardwajparth51
Copy link
Author

@jenkins-plone-org please run jobs

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check whether this matches when the ObjectCreatedEvent is triggered in other places where items are created in Plone.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doesn't fire IObjectCreatedEvent

3 participants