fix(presets): coerce non-string catalog tags before joining - #3743
Merged
mnriem merged 2 commits intoJul 27, 2026
Conversation
Preset catalog payloads are user-editable YAML/JSON, so a `tags:` list can legitimately contain non-strings (e.g. numeric tags). The preset list/search/info display paths and the catalog search backend joined tags with a raw `", ".join(...)` / used `t.lower()`, which raised `TypeError: sequence item N: expected str instance, int found` (or `AttributeError` on `.lower()`) and crashed the command. Sibling command surfaces already guard this — extensions, integrations, and workflows coerce with `str(t) for t in ...`. This aligns presets: - `_commands.py`: `preset list`, `preset search`, and both `preset info` branches now join `str(t) for t in ...`. - `__init__.py` `PresetCatalog.search`: tag filter uses `str(t).lower()` and the searchable-text join coerces tags to `str`. Adds regression tests driving `preset search` and `preset info` through CliRunner with numeric tags; both fail before the fix with the TypeError. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens preset tag handling against non-string catalog values.
Changes:
- Coerces tags to strings during search, filtering, and display.
- Adds CLI regression tests for numeric tags.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/presets/__init__.py |
Normalizes tags during searches. |
src/specify_cli/presets/_commands.py |
Normalizes displayed tags. |
tests/test_presets.py |
Tests numeric tags in search and info. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (3)
src/specify_cli/presets/_commands.py:291
- A catalog tag may itself be a JSON list; after
str()its brackets are interpreted as Rich markup and can raise a markup/style error. This means the search path still crashes for some non-string tags. Escape the complete joined value before printing it.
tags_str = ", ".join(str(t) for t in pack["tags"])
src/specify_cli/presets/_commands.py:382
- The local-info path still feeds the bracketed representation of nested non-string YAML tags directly to Rich, where it can be parsed as invalid markup and crash. Escape the joined tag text before rendering it.
console.print(f" Tags: {', '.join(str(t) for t in local_pack.tags)}")
src/specify_cli/presets/_commands.py:418
- The catalog-info path still treats the string representation of non-string tags as Rich markup. For example, a nested-list tag produces bracketed text and can fail during rendering, so this does not fully satisfy the no-crash behavior. Escape the joined value before printing it.
console.print(f" Tags: {', '.join(str(t) for t in pack_info['tags'])}")
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Medium
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (3)
src/specify_cli/presets/_commands.py:291
- The coerced value is still passed to Rich as markup. A non-string tag such as a nested list or mapping produces brackets in its
str()representation, which Rich may interpret as a style tag and reject; crafted catalog data can also inject terminal styling or links. Escape the joined value as the list command already does.
tags_str = ", ".join(str(t) for t in pack["tags"])
src/specify_cli/presets/_commands.py:382
- String coercion alone does not make arbitrary YAML tag values safe for Rich markup parsing. For example, a nested list is rendered with brackets that can be parsed as an invalid style and still crash
preset info; user-controlled markup can also alter terminal output. Escape the joined text before interpolation.
console.print(f" Tags: {', '.join(str(t) for t in local_pack.tags)}")
src/specify_cli/presets/_commands.py:418
- This catalog path now accepts arbitrary non-string tag values but feeds their string representations directly to Rich. Bracket-containing values can be interpreted as markup (and potentially raise a style parsing error), so this does not fully satisfy the goal of preventing malformed tags from crashing display. Escape the joined string consistently with
preset list.
console.print(f" Tags: {', '.join(str(t) for t in pack_info['tags'])}")
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Medium
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@-