#61970 closed defect (bug) (fixed)
Fatal error: Attempt to read property "ID" on null in /src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | normal | Version: | 6.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests has-testing-info |
Focuses: | template, rest-api | Cc: |
Description
This error occurs when a user tries to fetch autosave posts or revisions for a template (template part) that is file-based and does not have an associated entity in the posts table.
The returned HTTP code is 403, which is also incorrect.
Both the fatal error and the HTTP code need to be fixed.
Attachments (4)
Change History (13)
This ticket was mentioned in PR #7272 on WordPress/wordpress-develop by @antonvlasenko.
6 months ago
#2
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
Trac ticket: https://core.trac.wordpress.org/ticket/61970
#3
@
4 months ago
- Keywords has-testing-info added
Steps to test https://github.com/WordPress/wordpress-develop/pull/7272:
- On a fresh installation of WordPress, activate the
Twenty Twenty-Four
theme. - Send GET requests to the following endpoints:
/wp-json/wp/v2/templates/twentytwentyfour//search/revisions/1
/wp-json/wp/v2/templates/twentytwentyfour//search/autosaves
/wp-json/wp/v2/template-parts/twentytwentyfour//header/revisions/1
/wp-json/wp/v2/template-parts/twentytwentyfour//header/autosaves
- Observe that there are no REST API-related fatal PHP errors in the logs and that you receive the following REST API responses:
{ "code": "rest_invalid_template", "message": "Templates based on theme files can't have revisions.", "data": { "status": 400 } }
P.S. While manual testing is important, the aforementioned PR contains unit tests that verify the endpoint returns the correct response.
@antonvlasenko commented on PR #7272:
4 months ago
#4
This is looking good so for. Needs testing.
Thank you for the review, @spacedmonkey.
I’ve added testing instructions and fixed the failing PHPUnit tests.
#5
@
4 months ago
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/7272
Environment
- WordPress: 6.7-beta2-59195-src
- PHP: 8.3.3
- Server: Apache/2.4.57 (Unix) PHP/8.3.3
- Database: mysqli (Server: 5.7.43 / Client: mysqlnd 8.3.3)
- Browser: Safari 18.0 (macOS)
- Theme: Twenty Twenty-Four 1.2
- MU-Plugins: None activated
- Plugins:
- Datetime
- Gutenberg 19.1.0
- WordPress Beta Tester 3.5.3
Actual Results
- ✅ Template revisisions endpoint returns correct HTTP response code (400) for files based templates and template parts.
- ✅ Template autosaves endpoint returns correct HTTP response code (400) for files based templates and template parts.
Supplemental Artifacts
P.S. Apologies for the visual noise caused by the attached files below.
#6
@
4 months ago
- Milestone changed from Awaiting Review to 6.8
Thanks for the patch, and the testing. Added 6.8 milestone to get this in early next cycle once we're out of 6.7 RC!
#7
@
5 weeks ago
- Owner set to swissspidy
- Resolution set to fixed
- Status changed from new to closed
In 59605:
@swissspidy commented on PR #7272:
5 weeks ago
#8
Committed in https://core.trac.wordpress.org/changeset/59605
Props to @Mamaduka for discovering this issue.