Opened 7 years ago
Last modified 7 years ago
#48410 new defect (bug)
`wp_insert_post()` can result in duplicate post data
| Reported by: | henry.wright | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Posts, Post Types | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
If 2 identical calls to wp_insert_post() are made close enough together, 2 posts are added to the database instead of 1. These posts differ by post ID only. The slug for example is the same.
This seems to happen because wp_insert_post() does a fair amount of processing before the database write takes place. The check to determine if a post already exists can be _stale_ at the point of insertion.
Change History (5)
#4
@
7 years ago
Sure @davidbaumwald
If a website user requests a post by visiting the post permalink and the post doesn't exist in our WordPress install, we send a request to an internal system to see if data is available to import. If data is available the internal system responds with the data and wp_insert_post() is called immediately after checking again if the post exists
The duplicate issue happens when we are under heavy load and wp_insert_post() is called with the same arguments in a short space of time
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@henrywright Thanks for the ticket! Can you provide a bit more background on the use-case in this instance where you're having some concurrency of post insertions? A code sample would be really helpful as well.