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

Attempt to create 404 template from Site Editor results in 400 Bad Request #30135

Closed
bobbingwide opened this issue Mar 23, 2021 · 4 comments
Closed
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended

Comments

@bobbingwide
Copy link
Contributor

Description

While attempting to follow Call #3 instructions for #fse-outreach-experiment, rather than using TT1 blocks I used my own experimental FSE theme and tried to create the 404 template using Site Editor.
This resulted in a 400 Bad Request.

Step-by-step reproduction instructions

  1. Using an FSE theme that doesn't have a 404.html template invoke the Site Editor.
  2. Inspect the page and view the Network tab.
  3. Select the Show template details drop down beside Index and choose Browse all templates
  4. Click on + Add template
  5. Choose the 404 template
  6. Notice the 400 response
  7. View the Response
{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): slug",
    "data": {
        "status": 400,
        "params": {
            "slug": "slug does not match pattern [a-zA-Z_\\-]+."
        },
        "details": {
            "slug": {
                "code": "rest_invalid_pattern",
                "message": "slug does not match pattern [a-zA-Z_\\-]+.",
                "data": null
            }
        }
    }
}

Expected behaviour

The 404.html template should have been created.

Actual behaviour

In the Site Editor nothing appeared to happen.
The request payload was

cf=parse_request,rest_pre_echo_response 9723 9 0 2097152/2097152 256M F=437 HTTP_RAW_POST_DATA {"content":"<!-- wp:template-part {\"slug\":\"header\",\"theme\":\"sb\",\"tagName\":\"header\",\"align\":\"center\"} /-->\n\n<!-- wp:template-part {\"slug\":\"template-part\",\"theme\":\"sb\",\"className\":\"main-menu\"} /-->\n\n<!-- wp:columns -->\n<div class=\"wp-block-columns\"><!-- wp:column {\"width\":\"66.66%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:66.66%\"><!-- wp:template-part {\"slug\":\"template-part-3\",\"theme\":\"sb\",\"tagName\":\"main\"} /-->\n\n<!-- wp:template-part {\"slug\":\"template-part-4\",\"theme\":\"sb\",\"tagName\":\"section\"} /--></div>\n<!-- /wp:column -->\n\n<!-- wp:column {\"width\":\"33.33%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:33.33%\"><!-- wp:template-part {\"slug\":\"template-part-2\",\"theme\":\"sb\",\"tagName\":\"aside\"} /-->\n\n<!-- wp:categories /--></div>\n<!-- /wp:column --></div>\n<!-- /wp:columns -->\n\n<!-- wp:query /-->\n\n<!-- wp:query {\"queryId\":1,\"query\":{\"offset\":0,\"postType\":\"post\",\"categoryIds\":[],\"tagIds\":[],\"order\":\"desc\",\"orderBy\":\"date\",\"author\":\"\",\"search\":\"\",\"sticky\":\"\",\"perPage\":60,\"inherit\":true}} -->\n<!-- wp:query-loop -->\n<!-- wp:post-title {\"isLink\":true} /-->\n\n<!-- wp:post-excerpt /-->\n<!-- /wp:query-loop -->\n<!-- /wp:query -->","excerpt":"Template shown when no content is found.","slug":"404","status":"publish","title":"404"}

Screenshots or screen recording (optional)

image

Code snippet (optional)

WordPress information

  • WordPress version: 5.7
  • Gutenberg version: 10.2.1
  • Are all plugins except Gutenberg deactivated? No
  • Are you using a default theme (e.g. Twenty Twenty-One)? No

Device information

  • Device: Desktop
  • Operating system: Windows 10
  • Browser: Chrome
@bobbingwide
Copy link
Contributor Author

bobbingwide commented Mar 23, 2021

When reproducing the problem I also noticed a Warning message issued while creating the single-post template.

C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(279:2) bw_trace_error_handler(1) 52 3 2021-03-23T10:07:36+00:00 0.132292 0.009391 cf=parse_request 9702 9 0 2097152/2097152 256M F=437 err Array

    [0] => (integer) 2
    [1] => (string) "Warning: Attempt to read property "slug" on null"
    [2] => (string) "C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\class-wp-rest-templates-controller.php"
    [3] => (integer) 331

0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:286 0
2. bw_trace_error_handler(2,Attempt to read property "slug" on null,C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\class-wp-rest-templates-controller.php,331) C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\class-wp-rest-templates-controller.php:331 4
3. prepare_item_for_database(object) C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\class-wp-rest-templates-controller.php:242 1
4. create_item(object) C:\apache\htdocs\bigram\wp-includes\rest-api\class-wp-rest-server.php:1139 1
5. respond_to_request(object,/wp/v2/templates,array,unsupported) C:\apache\htdocs\bigram\wp-includes\rest-api\class-wp-rest-server.php:985 4
6. dispatch(object) C:\apache\htdocs\bigram\wp-includes\rest-api\class-wp-rest-server.php:412 1
7. serve_request(/wp/v2/templates) C:\apache\htdocs\bigram\wp-includes\rest-api.php:354 1
8. rest_api_loaded(object) C:\apache\htdocs\bigram\wp-includes\class-wp-hook.php:292 1
9. apply_filters(,array) C:\apache\htdocs\bigram\wp-includes\class-wp-hook.php:316 2
10. do_action(array) C:\apache\htdocs\bigram\wp-includes\plugin.php:551 1
11. do_action_ref_array(parse_request,array) C:\apache\htdocs\bigram\wp-includes\class-wp.php:388 2
12. parse_request() C:\apache\htdocs\bigram\wp-includes\class-wp.php:750 1
13. main() C:\apache\htdocs\bigram\wp-includes\functions.php:1291 1
14. wp C:\apache\htdocs\bigram\wp-blog-header.php:16 0
15. require(C:\apache\htdocs\bigram\wp-blog-header.php) C:\apache\htdocs\bigram\index.php:17 1

The HTTP_RAW_POST_DATA ( request payload) was

C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(504:0) bw_trace_http_raw_post_data(2) 60 3 2021-03-23T10:07:37+00:00 0.289281 0.001545 cf=parse_request,rest_pre_echo_response 10413 45 0 2097152/2097152 256M F=438 HTTP_RAW_POST_DATA {"content":"<!-- wp:template-part {\"slug\":\"header\",\"theme\":\"sb\",\"tagName\":\"header\",\"align\":\"center\"} /-->\n\n<!-- wp:template-part {\"slug\":\"template-part\",\"theme\":\"sb\",\"className\":\"main-menu\"} /-->\n\n<!-- wp:columns -->\n<div class=\"wp-block-columns\"><!-- wp:column {\"width\":\"66.66%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:66.66%\"><!-- wp:template-part {\"slug\":\"template-part-3\",\"theme\":\"sb\",\"tagName\":\"main\"} /-->\n\n<!-- wp:template-part {\"slug\":\"template-part-4\",\"theme\":\"sb\",\"tagName\":\"section\"} /--></div>\n<!-- /wp:column -->\n\n<!-- wp:column {\"width\":\"33.33%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:33.33%\"><!-- wp:template-part {\"slug\":\"template-part-2\",\"theme\":\"sb\",\"tagName\":\"aside\"} /-->\n\n<!-- wp:categories /--></div>\n<!-- /wp:column --></div>\n<!-- /wp:columns -->\n\n<!-- wp:query /-->\n\n<!-- wp:query {\"queryId\":1,\"query\":{\"offset\":0,\"postType\":\"post\",\"categoryIds\":[],\"tagIds\":[],\"order\":\"desc\",\"orderBy\":\"date\",\"author\":\"\",\"search\":\"\",\"sticky\":\"\",\"perPage\":60,\"inherit\":true}} -->\n<!-- wp:query-loop -->\n<!-- wp:post-title {\"isLink\":true} /-->\n\n<!-- wp:post-excerpt /-->\n<!-- /wp:query-loop -->\n<!-- /wp:query -->","excerpt":"Template used to display a single post type.","slug":"single-post","status":"publish","title":"Post"}

This Warning can be produced when $request['id'] is not set, so $template is assigned to null.

$template           = $request['id'] ? gutenberg_get_block_template( $request['id'], $this->post_type ) : null;

@carolinan
Copy link
Contributor

I believe this is the same problem as in #28662 ?

@bobbingwide
Copy link
Contributor Author

bobbingwide commented Mar 23, 2021

It could be the same underlying issue, but I didn't get any feedback.
I also note that after editing the 404 template using the site editor, the slug is 404.
So either Ari's issue has been fixed OR it's a different problem.

Q. Should I raise the second comment ( #30135 (comment) ) as a separate issue as the problem's in a slightly different section of code.

@skorasaurus skorasaurus added the [Type] Bug An existing feature does not function as intended label Mar 23, 2021
@annezazu annezazu added [Feature] Full Site Editing [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Mar 23, 2021
@Mamaduka
Copy link
Member

Mamaduka commented May 1, 2022

The issue should be fixed now. See #37579.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants