Skip to content

Compare category IDs as ints in _get_category_by_id#38

Merged
jeherve merged 1 commit into
m:mainfrom
jeherve:fix/wpcom-category-id-int-coercion
Jun 3, 2026
Merged

Compare category IDs as ints in _get_category_by_id#38
jeherve merged 1 commit into
m:mainfrom
jeherve:fix/wpcom-category-id-int-coercion

Conversation

@jeherve

@jeherve jeherve commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

_get_category_by_id matched with c.get('ID') == term_id. The WP.com API sometimes returns term IDs as strings (the tree builder already coerces for this reason), so a string '49' in the cache wouldn't equal an int 49 and the lookup returned None, a spurious 404 that aborts an apply or restore mid-run.

This coerces both sides to int before comparing. I added a regression test with a string-typed ID from the API.

While testing against a live Jetpack site, passing a string term ID to set_post_categories resolved correctly.

Testing

  • python3 -m unittest discover tests — green
  • ruff check lib/ tests/ — clean

_get_category_by_id matched with 'c.get("ID") == term_id'. The WP.com API
sometimes returns term IDs as strings (the tree builder already coerces for
this reason), so a string '49' in the cache would not equal an int 49 and
the lookup returned None — a spurious 404 that aborts an apply or restore
mid-run. Coerce both sides to int before comparing. Add a regression test
with a string-typed ID from the API.
@jeherve jeherve self-assigned this Jun 3, 2026
@jeherve jeherve merged commit 8cdbeef into m:main Jun 3, 2026
3 checks passed
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.

1 participant