Skip to content

fix: Request taxonomies with view context for Author/Editor roles - #23291

Merged
dcalhoun merged 6 commits into
trunkfrom
fix/cmm-2398-author-category-picker
Sep 4, 2026
Merged

fix: Request taxonomies with view context for Author/Editor roles#23291
dcalhoun merged 6 commits into
trunkfrom
fix/cmm-2398-author-category-picker

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Sep 3, 2026

Copy link
Copy Markdown
Member

Description

Fix CMM-2398.

An Author or Contributor on an Atomic or self-hosted site got a blocking "Category refresh error" when opening the category picker in the post editor, and could not assign categories at all. Switching the user to Editor cleared it.

Root cause. TaxonomyRsApiRestClient.fetchTerms listed terms with listWithEditContext, i.e. GET /wp/v2/categories?context=edit. WP core gates that context on the taxonomy's edit_terms capability — manage_categories for category, manage_post_tags for post_tag — which Authors and Contributors do not hold, so the API answered 403 rest_forbidden_context. The client turned that into a generic error and the picker reported a refresh failure instead of listing the site's terms.

Listing terms is a read, and the view context returns every field this client maps (no term field is edit-only, and name/description are identical across contexts), so it now requests context=view.

Scope. The taxonomies_rest_api_migration flag is rolled out to 50% of users on 26.9+, so this affects Authors and Contributors on Atomic and self-hosted sites, for both categories and tags. The tags breakage was silent: TagsFragment ignores fetch errors, so tag suggestions simply came back empty.

Testing instructions

Note

Requires a test user set to Author on an Atomic site. The taxonomies_rest_api_migration feature flag must be enabled in the dev menu.

Note that SelectCategoriesActivity only fetches when its list is empty, so clear app storage or sign out and back in before each cold-cache run — a warm cache hides the bug.

Categories (the reported issue):

  1. On trunk, as the Author, open a post → Post Settings → Categories.
  • Verify the blocking "Category refresh error" appears and no categories are listed
  1. Switch to this branch, clear app storage, sign in as the same Author, and repeat.
  • Verify the category list loads
  • Verify selecting categories persists back to the post

Tags (same fix, no cache clearing needed):

  1. As the Author, open a post → Post Settings → Tags and type a letter.
  • Verify existing tag suggestions appear (on trunk they are silently empty)

Refresh failure handling (unchanged from trunk):

  1. With categories already loaded, use a proxy to fail */categories* with a 500, then pull to refresh.
  • Verify the cached list stays on screen and a "Category refresh error" toast appears

Regressions:

  1. As an Editor or Admin on the same Atomic site, open the category picker and create a category from the "+" menu.
  • Verify the list loads and creation still works
  1. Open Site Settings → Categories.
  • Verify create, rename and delete still work1
  1. Repeat the category picker check on a WP.com Simple site and on a self-hosted site with an application password.
  • Verify both still list categories

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG

Footnotes

  1. Deleting is broken: https://github.com/wordpress-mobile/WordPress-Android/issues/23293

@dcalhoun dcalhoun changed the title CMM-2398: Request taxonomy terms in the view context fix: Request taxonomies with view context for Author/Editor roles Sep 3, 2026
@wpmobilebot

wpmobilebot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23291-176af40
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit176af40
Installation URL1uh3u2l2go69g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23291-176af40
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit176af40
Installation URL3bkf32549uej8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.78378% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.04%. Comparing base (9fa0185) to head (176af40).
⚠️ Report is 1 commits behind head on trunk.

Files with missing lines Patch % Lines
...ork/rest/wpapi/taxonomy/TaxonomyRsApiRestClient.kt 83.78% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #23291   +/-   ##
=======================================
  Coverage   38.04%   38.04%           
=======================================
  Files        2353     2353           
  Lines      128876   128893   +17     
  Branches    17940    17949    +9     
=======================================
+ Hits        49030    49043   +13     
  Misses      75827    75827           
- Partials     4019     4023    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcalhoun
dcalhoun force-pushed the fix/cmm-2398-author-category-picker branch from 26fd45e to 08a3f76 Compare September 3, 2026 19:15
dcalhoun and others added 3 commits September 3, 2026 15:34
Listing categories and tags over wordpress-rs used context=edit, which WP
core gates on the taxonomy's edit_terms capability (manage_categories /
manage_post_tags). Authors and Contributors hold neither, so the REST API
answered 403 rest_forbidden_context and the post editor's picker reported
a refresh error instead of listing the site's terms. The listing is a read
and the view context carries every field this client maps, so request that
instead.

Term failures now also map 401 and 403 to TaxonomyErrorType.UNAUTHORIZED,
keeping the parity TaxonomyXMLRPCClient already has as the wp-rs path
replaces it. No caller branches on the type yet, so this shows up only in
the taxonomy log lines. Failures are logged through toLogErrorString()
rather than interpolating the raw result, which put response bodies in the
log.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
notifyFailedDeleting() wrote one line for two different failures, and once it
took the request result it logged a literal null for the case where the request
succeeded and the API reported the term as not deleted. Log at the call sites
instead, where the result is still in scope, so the two are distinguishable,
and let the function take the error it dispatches.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
createTestAnyTermWithViewContext() was a field-for-field copy of
createTestAnyTermWithEditContext(), so every change to the term under test had
to be made twice and a test updating only one would assert against divergent
data. The generated edit and view types share no supertype, so keep the values
in one place and build each type from them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3eKPoHZwqK4AP3GQBSgEG
@dcalhoun
dcalhoun force-pushed the fix/cmm-2398-author-category-picker branch from 08a3f76 to 6fdfbfe Compare September 3, 2026 19:35
@dcalhoun
dcalhoun marked this pull request as ready for review September 3, 2026 19:48
@dcalhoun
dcalhoun requested a review from adalpari September 3, 2026 19:48
@dcalhoun dcalhoun added this to the 27.2 milestone Sep 3, 2026

@adalpari adalpari left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works as expected!

@dcalhoun
dcalhoun enabled auto-merge (squash) September 4, 2026 12:51
@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

wordpress-rs 0.8.0 removed WpRequestResult.toLogErrorString(), which these
call sites used to describe a failure without its response body. The library
now offers a client-level error logger instead, but FluxC's WpApiClientProvider
supplies none, so interpolating the result would write the whole body to the
log.

Log the TaxonomyError each site already maps: it names the failure and carries
the server's message, and it omits the body.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dcalhoun
dcalhoun disabled auto-merge September 4, 2026 14:07
@dcalhoun
dcalhoun merged commit 88310c2 into trunk Sep 4, 2026
23 checks passed
@dcalhoun
dcalhoun deleted the fix/cmm-2398-author-category-picker branch September 4, 2026 14:07
dcalhoun added a commit that referenced this pull request Sep 4, 2026
Resolves an import conflict in TaxonomyRsApiRestClientTest: trunk's #23291
moved the list request to the view context, so the list response type is
TermsRequestListWithViewContextResponse, while this branch's delete-by-remote-id
test stubs the request executor and needs TermsRequestExecutor and
UniffiWpApiClient.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011pj4FNhM3TFx83R5uDSuYh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants