Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Metadata filters crash on keys containing dots or other special characters

未关闭
#3,179 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, sql, sqlalchemy, sqlite
领域
databases

调研方向

The bug is in the metadata condition builders in pyrit/memory/sqlite_memory.py and pyrit/memory/azure_sql_memory.py, specifically _get_seed_metadata_conditions and _get_message_pieces_prompt_metadata_conditions, where the key is interpolated into the JSON path and the bind name. Read the label fix from #3063 for the pattern. PR #3180 is already open against this, so check it before starting. Done means a dotted key like a.b filters correctly in both backends.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

Filtering seeds or message pieces by a prompt_metadata key that contains a dot (or any character outside a plain SQL bind name, like a hyphen or a space) crashes the query instead of filtering.

In sqlite_memory.py and azure_sql_memory.py, _get_seed_metadata_conditions and _get_message_pieces_prompt_metadata_conditions build the SQL with the key interpolated into both the JSON path and the bind parameter name:

f"JSON_EXTRACT(prompt_metadata, '$.{key}') = :{key}"

For a key like a.b, SQLAlchemy parses :a.b as a parameter named a followed by literal text, so the later bindparams() call raises ArgumentError: This text() construct doesn't define a bound parameter named 'a.b'.

This is the same class of problem #3063 fixed for memory labels, where the accepted fix quotes the JSON path and uses indexed parameter names.

Steps/Code to Reproduce
import asyncio, tempfile
from pyrit.memory.sqlite_memory import SQLiteMemory
from pyrit.models import SeedPrompt

async def main():
    memory = SQLiteMemory(db_path=tempfile.mktemp(suffix=".db"), verbose=False)
    await memory.add_seeds_to_memory_async(seeds=[
        SeedPrompt(value="dotted", data_type="text", dataset_name="t", metadata={"a.b": "v1"}),
    ], added_by="repro")
    got = await memory.get_seeds_async(metadata={"a.b": "v1"})  # raises ArgumentError
    print(got)

asyncio.run(main())
Expected Results

The filter matches the stored seed by the literal metadata key a.b and returns it.

Actual Results
sqlalchemy.exc.ArgumentError: This text() construct doesn't define a bound parameter named 'a.b'
Screenshots

N/A

Versions

OS: macOS
Python version: 3.14
PyRIT version: installed from main (66c41fa)

主要语言
Python
星标
4.6k
派生
944
平均合并
2 天 18 小时
30 天内合并 PR
358

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/PyRIT 的其他 Issue

查看 microsoft/PyRIT 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。