fix: on PostgreSQL, searching automations or filtering models by a non-ASCII word finds nothing (#31423)

On PostgreSQL with ENABLE_ORJSON off (the default), searching automations by a word from their prompt, or filtering models by a tag, found nothing when the word was non-ASCII, for example Chinese. SQLite, and PostgreSQL with ENABLE_ORJSON on, were fine. With the default setting non-ASCII text is saved as \uXXXX codes, and PostgreSQL reads the backslash in a search pattern as a special character, so the search never matched. Special characters in the search text are now taken literally, so these searches work on both databases, and a % or _ typed into them now matches only itself.

Fixes #31422
This commit is contained in:
Classic298 2026-09-27 21:09:54 +02:00 • committed by GitHub
parent 6c2cdd0424
commit d6b19dcaa1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 3 deletions

View file

@ -195,7 +195,7 @@ class AutomationTable:
stmt = stmt.filter(
or_(
Automation.name.ilike(f'%{query}%'),
*(data_text.ilike(f'%{variant}%') for variant in json_text_variants(query)),
*(data_text.icontains(variant, autoescape=True) for variant in json_text_variants(query)),
)
)

View file

@ -392,7 +392,9 @@ class ModelsTable:
else:
meta_text = func.lower(cast(Model.meta, String))
variants = json_text_variants(tag.lower())
stmt = stmt.filter(or_(*(meta_text.like(f'%"{variant}"%') for variant in variants)))
stmt = stmt.filter(
or_(*(meta_text.contains(f'"{variant}"', autoescape=True) for variant in variants))
)
order_by = filter.get('order_by')
direction = filter.get('direction')

View file

@ -346,7 +346,10 @@ class PromptsTable:
# Fallback for dialects with no JSON array function: LIKE on the text.
tags_text = func.lower(cast(Prompt.tags, String))
tag_clause = or_(
*(tags_text.like(f'%"{variant}"%') for variant in json_text_variants(tag_lower))
*(
tags_text.contains(f'"{variant}"', autoescape=True)
for variant in json_text_variants(tag_lower)
)
)
tag_lower = None