[wp-trac] [WordPress Trac] #47552: post_name when inserting is not guaranteed to be unique
WordPress Trac
noreply at wordpress.org
Fri Sep 5 16:15:59 UTC 2025
#47552: post_name when inserting is not guaranteed to be unique
-------------------------------------------------+-------------------------
Reporter: domslee | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Posts, Post Types | Version:
Severity: normal | Resolution:
Keywords: has-test-info needs-patch needs- | Focuses:
unit-tests |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: => has-test-info needs-patch needs-unit-tests
* milestone: Awaiting Review => Future Release
Comment:
== Reproduction Report
=== Description
✅ This report validates whether the issue can be reproduced.
=== Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.29
- Server: nginx/1.29.1
- Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
- Browser: Chrome 140.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.3
- MU Plugins: None activated
- Plugins:
* BBB Testing Dolly
* Test Reports 1.2.0
=== Testing Instructions
1. If running `wordpress-develop` you will need a couple tweaks and the
`wpdev-docker-images` WordPress repo. Check these two patches
([https://core.trac.wordpress.org/attachment/ticket/47552/wpdev-docker-
images-47552.patch wpdev-docker-images patch] and
[https://core.trac.wordpress.org/attachment/ticket/47552/docker-compose-
test-47552.patch docker compose patch] to set everything up.
2. Add the plugin in the OP
3. Run with WP CLI `cli wp my_plugin`
4. 🐞 Two posts are created with the exact same `post_name`
=== Actual Results
1. ✅ Error condition occurs (reproduced).
=== Additional Information
Replying to [comment:2 domslee]:
> Should we consider a UNIQUE constraint on (post_name, post_type,
post_status)?
There could be matching names as long as they are hierarchically in
different levels. So we could have two `post_type` = `page`, two
`post_status` = `publish` and two `post_name` identical. At best this
could be done only if `post_type` = `post` (or for non hierarchical post
types). But definitely not as a SQL `UNIQUE` key
To test this I've added two files, one to add for a php 8.2 image in
`wpdev-docker-images` and little tweak for the current `docker-
compose.yml` to run the semaphores. Main problem here is that the default
images are not well prepared to run scripts with extra libraries. I've
added these two files, in case I have to refer back to this ticket, and
I'm able to test this without having to spend the time I have spent to
learn how to set up this in the `wordpress-develop` environment`.
So finally, after some testing and reviewing of this, I can confirm that
the possibility to do this is there.
I'm unsure if #61996 is related because happens the same, but in `page`
type, and playing around with parent-child relationships (i mean real WP
parental relationship, not thread relationships like in the CLI plugin).
Also this is being tricker to test, because since its running under wp-cli
conditions, I'm unable to run with xdebug to clearly see the order of the
operations in `wp_insert_post`
Definitely not an easy patch here at first glance. I would like to hear
more opinions. @peterwilsoncc can you take a look at this when you have a
minute?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47552#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list