mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-15 00:31:58 +00:00
选对象按名字查改用 ilike(复核 L3):PostgreSQL 上 LIKE 分 ASCII 大小写、SQLite 不分,两种库说法不一;% 和 _ 照 runs._like 转义、按字面匹配。补测试
This commit is contained in:
@@ -618,7 +618,10 @@ async def trigger_options(event: str | None = None, q: str | None = None, select
|
||||
async def page(model: Any, *conds: Any) -> tuple[list[Any], bool]:
|
||||
query = select(model).where(*conds)
|
||||
if words:
|
||||
query = query.where(model.name.contains(words, autoescape=True))
|
||||
# 名字里含这几个字,不分大小写:PostgreSQL 上 LIKE 分 ASCII 大小写、SQLite 不分,一律 ilike(转义同 runs._like)
|
||||
from app.api.runs import _like
|
||||
|
||||
query = query.where(model.name.ilike(f"%{_like(words)}%", escape="\\"))
|
||||
rows = list((await session.execute(query.order_by(model.name, model.id).limit(limit + 1))).scalars())
|
||||
more = len(rows) > limit
|
||||
rows = rows[:limit]
|
||||
|
||||
@@ -169,3 +169,19 @@ async def test_a_window_ending_where_another_fire_already_is_still_fires():
|
||||
assert len(await fires(sid)) == 2
|
||||
assert [d.status for d in await deliveries(sid)] == ["fired", "fired"]
|
||||
assert TriggerDelivery is not None
|
||||
|
||||
|
||||
async def test_trigger_option_search_ignores_case_and_takes_wildcards_literally(client):
|
||||
"""按名字查不分大小写(PostgreSQL 上 LIKE 分 ASCII 大小写、SQLite 不分:一律 ilike),% 和 _ 按字面匹配、不当通配符。"""
|
||||
async with SessionLocal() as session:
|
||||
session.add_all([Workflow(name=n, graph={"nodes": [], "edges": []})
|
||||
for n in ("Weekly_Report 样例", "WeeklyXReport 样例", "满 100% 样例", "满 1000 样例")])
|
||||
await session.commit()
|
||||
|
||||
async def names(q: str) -> list[str]:
|
||||
r = await client.get("/api/schedules/trigger-options", params={"event": "workflow.finished", "q": q})
|
||||
assert r.status_code == 200, r.text
|
||||
return [o["name"] for o in r.json()["events"][0]["objects"]]
|
||||
|
||||
assert await names("weekly_report") == ["Weekly_Report 样例"], "大小写不分;_ 不匹配任意一个字"
|
||||
assert await names("100%") == ["满 100% 样例"], "% 不匹配任意几个字"
|
||||
|
||||
Reference in New Issue
Block a user