Skip to content

test: add regression coverage for Media pod REST save - #7594

Open
faisalahammad wants to merge 1 commit into
pods-framework:release/3.4.0from
faisalahammad:fix/6420-media-pod-rest-save
Open

test: add regression coverage for Media pod REST save#7594
faisalahammad wants to merge 1 commit into
pods-framework:release/3.4.0from
faisalahammad:fix/6420-media-pod-rest-save

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

Adds a regression test for the Media pod REST save path. A Pods custom field added to the Media (attachment) pod could be read via the WP REST API but could not be written: a POST to /wp/v2/media/<id> returned the field as [false] and the value never persisted. The same field worked on a custom post type.

Root cause was a lookup key mismatch in PodsRESTHandlers::save_handler(). register_rest_field( 'attachment', ... ) stores the field under the attachment key in the $wp_rest_additional_fields global, but the handler was keying by the pod name media, so the field was never matched during the save loop. The fix keying the lookup by the WP post type is already present in classes/PodsRESTHandlers.php.

The new test directly invokes save_handler() on a media pod and asserts the field is persisted. It fails if the lookup regresses to the pod name, locking the fix in place. No production code changes in this PR.

Related GitHub issue(s)

Fixes #6420

Testing instructions

  1. Run the wpunit REST group: ./vendor/bin/codecept run wpunit --group=pods-rest (covered by the existing wpunit matrix entry in .github/workflows/tests-php.yml).
  2. Confirm the 3 tests in this class pass.
  3. To confirm the test catches the original bug, revert the $type-vs-$pod_name lookup in PodsRESTHandlers::save_handler() (change $wp_rest_additional_fields[ $type ] back to $wp_rest_additional_fields[ $pod_name ] on lines 287 and 297) and re-run. should_save_field_on_media_pod_via_save_handler fails with '' != '42'. Restore the lookup to re-green.

Screenshots / screencast

None. No UI changes.

Changelog text for these changes

Bug: A Pods custom field on the Media (attachment) pod can now be updated via the WP REST API. #6420 (@faisalahammad)

PR checklist

@faisalahammad
faisalahammad changed the base branch from main to release/3.4.0 August 18, 2026 11:20
@faisalahammad

Copy link
Copy Markdown
Contributor Author

AI disclosure: this PR was written with Claude Opus 5 assistance, reviewed and tested by me.

Locks in the fix for pods-framework#6420. PodsRESTFields::register() maps the 'media' pod to the
'attachment' object type, so PodsRESTHandlers::save_handler() must look up
$wp_rest_additional_fields by object type rather than by pod name. Reverting that
lookup to the pod name leaves the array empty and this test fails, so it is a real
guard rather than a restatement.

Refs pods-framework#6420
@faisalahammad
faisalahammad force-pushed the fix/6420-media-pod-rest-save branch from 066a891 to 8a0699e Compare August 19, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot modify custom field via REST API if added to Media content type

1 participant