Skip to content

fix(presets): coerce non-string catalog tags before joining - #3743

Merged
mnriem merged 2 commits into
github:mainfrom
Noor-ul-ain001:fix/preset-nonstring-tags-crash
Jul 27, 2026
Merged

fix(presets): coerce non-string catalog tags before joining#3743
mnriem merged 2 commits into
github:mainfrom
Noor-ul-ain001:fix/preset-nonstring-tags-crash

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

@-

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>

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

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

Comment thread src/specify_cli/presets/_commands.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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.

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

@mnriem
mnriem merged commit 6136706 into github:main Jul 27, 2026
14 checks passed
@mnriem

mnriem commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

3 participants