Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when editing custom post type with non-Latin slug in Gutenberg: "You attempted to edit an item that doesn't exist." #67358

Closed
3 of 6 tasks
mafiayemakhfi opened this issue Nov 27, 2024 · 6 comments · Fixed by #67780
Labels
[Package] Core data /packages/core-data [Type] Bug An existing feature does not function as intended

Comments

@mafiayemakhfi
Copy link

Description

When attempting to edit a custom post type with a Persian slug in the Gutenberg editor, I encounter the error message:

"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"

The post is still accessible via its URL, and no data appears to be lost. This issue seems to be related to the handling of slugs containing non-Latin characters in the Gutenberg editor.

Step-by-step reproduction instructions

  1. Create a custom post type (CPT) with a Persian slug.
  2. Example: my_custom_post_type with a slug like ویدیو (or any Persian characters).
  3. Permalink structure should be /%postname%/ .
  4. Publish a post in that CPT.
  5. Attempt to edit the post using the Gutenberg editor by navigating to the post editing screen.
  6. The error message "You attempted to edit an item that doesn't exist" appears.
$video_labels = array(
            'name'                => _x('Videos', 'Post Type General Name', 'test'),
            'singular_name'       => _x('Video', 'Post Type Singular Name', 'test'),
            'menu_name'           => __('Videos', 'test'),
            'parent_item_colon'   => __('Video :', 'test'),
            'all_items'           => __('All Videos', 'test'),
            'view_item'           => __('View Video', 'test'),
            'add_new_item'        => __('Add Video', 'test'),
            'add_new'             => __('Add Video', 'test'),
            'edit_item'           => __('Edit Video', 'test'),
            'update_item'         => __('Update Video', 'test'),
            'search_items'        => __('Search Video', 'test'),
            'not_found'           => __('Video Not Found', 'test'),
            'not_found_in_trash'  => __('No Video Found In Trash', 'test'),
        );

        // Register Video Post Type
        register_post_type(
            'video',
            array(
                'labels'        => $video_labels,
                'public'        => true,
                'supports'      => array ( 'comments', 'title', 'editor', 'thumbnail','revisions' ),
                'has_archive'   => true,
                'show_in_rest'  => true,
                'rewrite'       => array('slug' => 'ویدیو'),
                'taxonomies'    => array('category', 'post_tag', 'artist_cat'),
                'menu_icon'     => 'dashicons-video-alt3',
                'menu_position' => 5
            )
        );

Screenshots, screen recording, code snippet

No response

Environment info

WP Version 6.7.1
Site Language en_US
User Language en_US
Timezone +00:00
Home URL http://localhost
Site URL http://localhost
Permalink structure /%postname%/
Is this site using HTTPS? No
Is this a multisite? No
Can anyone register on this site? No
Is this site discouraging search engines? No
Default comment status Open
Environment type production
User count 1
Communication with WordPress.org WordPress.org is reachab

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@mafiayemakhfi mafiayemakhfi added the [Type] Bug An existing feature does not function as intended label Nov 27, 2024
@mafiayemakhfi mafiayemakhfi changed the title Error when editing custom post type with Persian slug in Gutenberg: "You attempted to edit an item that doesn't exist." Error when editing custom post type with non-Latin slug in Gutenberg: "You attempted to edit an item that doesn't exist." Nov 27, 2024
@SainathPoojary
Copy link
Contributor

Hey @mafiayemakhfi,

I confirm that I was able to reproduce the bug in the environment described below. I used the code snippet provided in the description to create a custom post type (CPT).

Environment

  • WordPress: 6.7.1
  • PHP: 8.1.29
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.29)
  • Browser: Chrome 131.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.0
  • MU Plugins: None activated
  • Plugins: Test Plugin
2024-11-28.10-11-34.mp4

@himanshupathak95
Copy link
Contributor

Hey @mafiayemakhfi, Thanks for bringing this up.

I was able to reproduce the issue following the above-mentioned steps. Here are the details -

Environment

  • WordPress: 6.8-alpha-59366
  • PHP: 8.2.25
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.4.3-MariaDB-ubu2404 / Client: mysqlnd 8.2.25)
  • Browser: Chrome 131.0.0.0
  • OS: macOS

Screencast -

Screen.Recording.2024-11-28.at.11.02.12.mov

@Juzar10
Copy link
Contributor

Juzar10 commented Dec 10, 2024

The issue occurs because of the encoding error for the api-fetch module, which the editor is getting called for.

PR: #67780

Above PR fixes the issue by correcting the encoding for the header where the link is getting used which might have the Persian slug.

@t-hamano
Copy link
Contributor

The same issue was reported in #68793. After my investigation, it seems that this issue was caused by #63430.

@Mamaduka
Copy link
Member

As noted in #67780, the problem comes from the apiFetch package. It became more evident after #63430, which disabled parsing for the request.

@Mamaduka
Copy link
Member

Mamaduka commented Jan 29, 2025

I discussed this with @TimothyBJacobs, and this is probably a REST API or Rewrites core component issue.

Here's what is happening:

  • When a resource data is preloaded for editors, apiFetch middleware will try to reconstruct Response from a JSON object.
  • The "Link" header contains a non-Latin post-type rewrite slug, and the Response web API throws an error since it only works with Latin/ISO-8859-1 chars.
  • The resource request fails, and the editor assumes it's missing from DB.

Possible solutions:

Screenshot

Currently, preloaded headers look like this:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging a pull request may close this issue.

6 participants