Skip to content

feat(api): add /type/tag to /api/new allowed types - #13088

Merged
mekarpeles merged 4 commits into
masterfrom
fix/api-new-tag-type
Jul 2, 2026
Merged

mekarpeles merged 4 commits into
masterfrom
fix/api-new-tag-type

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

Summary

Adds /type/tag to the allowlist in the /api/new endpoint's verify_types check.

Previously, api-group bots could write to existing tag documents via save_many but had no way to create new ones — /api/new rejected /type/tag with BadRequest, and there is no other external path to Infogami's new_key() which assigns OLIDs.

With this change, creating a tag via the API works as expected:

# POST /api/new with Opt/42-comment headers
{"type": {"key": "/type/tag"}, "name": "Horror", "tag_type": "subject"}
# → 200 ["/tags/OL2T"]

Related

  • Requires /tags namespace document with child_permission: /permission/tag-editors to be in place (applied directly to production Infogami — /usergroup/api added to writers)
  • Companion fix in openlibrary-client: #443 — sets Content-Type: application/json on session to pass ModSecurity WAF rule 920340

Testing

docker compose run --rm home python -m pytest openlibrary/plugins/openlibrary/tests/ -x -v

Allows api-group bots to create new Tag documents via /api/new,
which assigns a new OLID via new_key() and saves the document.
Previously /type/tag was absent from the allowlist, forcing callers
to hardcode OLIDs when using save_many.
Copilot AI review requested due to automatic review settings July 1, 2026 23:51

Copilot AI 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.

Pull request overview

This PR updates the legacy Infogami /api/new endpoint (implemented in the Open Library plugin) to allow creation of tag documents by adding /type/tag to the endpoint’s type allowlist, enabling API clients/bots to obtain new /tags/OL…T keys via new_key().

Changes:

  • Add /type/tag to the /api/new verify_types allowlist so tag documents can be created through the API.
  • Minor import reordering within openlibrary/plugins/openlibrary/code.py (no behavioral change observed from the import moves themselves).

@mekarpeles mekarpeles added the Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle. label Jul 2, 2026
mekarpeles and others added 2 commits July 2, 2026 12:04
Previously a missing 'key' field caused an opaque KeyError inside
infogami's process_many, surfaced as a generic 400 internal_error
with no actionable message. Now caught in OLConnection.save_many
and returned as a descriptive bad_data response before hitting infogami.
@mekarpeles

Copy link
Copy Markdown
Member Author

https://openlibrary.org/permission/tag-editors.json

"writers": [
{
"key": "[/usergroup/api](https://openlibrary.org/usergroup/api)"
},
{
"key": "[/usergroup/curators](https://openlibrary.org/usergroup/curators)"
},
{
"key": "[/usergroup/librarians](https://openlibrary.org/usergroup/librarians)"
},
{
"key": "[/usergroup/super-librarians](https://openlibrary.org/usergroup/super-librarians)"
},
{
"key": "[/usergroup/admin](https://openlibrary.org/usergroup/admin)"
}
],

@mekarpeles

Copy link
Copy Markdown
Member Author

This would be good to also have on local instances

@mekarpeles
mekarpeles merged commit 19bdb2d into master Jul 2, 2026
8 checks passed
@mekarpeles
mekarpeles deleted the fix/api-new-tag-type branch July 2, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants