lintsinghua / lintsinghua/DeepAudit
可能缺少对插入数据库数据的格式转换
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 850
- PR merge metrics
- No merged PRs in 30d
Description
快速扫描进度27/1000 就报错了,扫了两次也没有成功扫描完毕过
需要添加AI分析缓存功能,对相同模型相同的提示词应该返回相同的结果,避免断点后无法继续扫描
中断后一直没有动静了
```
(Background on this error at: https://sqlalche.me/e/20/dbapi) (Background on this error at: https://sqlalche.me/e/20/7s2a)
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1139, in __call__
await super().__call__(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/applications.py", line 107, in __call__
await self.middleware_stack(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 93, in __call__
await self.simple_response(scope, receive, send, request_headers=headers)
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 144, in simple_response
await self.app(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/app/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/app/.venv/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/routing.py", line 716, in __call__
await self.middleware_stack(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/routing.py", line 736, in app
await route.handle(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/routing.py", line 290, in handle
await self.app(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 120, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/app/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/app/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 107, in app
await response(scope, receive, send)
File "/app/.venv/lib/python3.12/site-packages/starlette/responses.py", line 167, in __call__
await self.background()
File "/app/.venv/lib/python3.12/site-packages/starlette/background.py", line 36, in __call__
await task()
File "/app/.venv/lib/python3.12/site-packages/starlette/background.py", line 21, in __call__
await self.func(*self.args, **self.kwargs)
File "/app/app/api/v1/endpoints/scan.py", line 221, in process_zip_task
await db.commit()
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/ext/asyncio/session.py", line 1000, in commit
await greenlet_spawn(self.sync_session.commit)
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 190, in greenlet_spawn
result = context.switch(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2030, in commit
trans.commit(_to_root=True)
File "", line 2, in commit
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.py", line 101, in _go
self._raise_for_prerequisite_state(fn.__name__, current_state)
File "/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 971, in _raise_for_prerequisite_state
raise sa_exc.PendingRollbackError(
sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlalchemy.dialects.postgresql.asyncpg.Error) : invalid input for query argument $68: 'c5fc' ('str' object cannot be interpreted as an integer)
[SQL: INSERT INTO audit_issues (id, task_id, file_path, line_number, column_number, issue_type, severity, title, message, description, suggestion, code_snippet, ai_explanation, status, resolved_by, resolved_at) VALUES ($1::VARCHAR, $2::VARCHAR, $3::VARCHAR ... 1117 characters truncated ... HAR, $79::VARCHAR, $80::TIMESTAMP WITH TIME ZONE) RETURNING audit_issues.created_at, audit_issues.id]
```
这是一个非常典型的 SQLAlchemy 异步会话(Async Session)错误,其根本原因在于数据类型不匹配。
核心错误分析
直接报错信息:
sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush.
含义:你试图调用 await db.commit() 提交事务,但 SQLAlchemy 检测到之前的“刷新”(flush,即准备发送 SQL 到数据库的过程)已经失败了。因为之前的失败,事务已经被自动回滚了,所以现在的 Session 处于“待回滚”状态,不能直接 commit,必须先执行 rollback()。
根本原因(Original exception):
(sqlalchemy.dialects.postgresql.asyncpg.Error) : invalid input for query argument $68: 'c5fc' ('str' object cannot be interpreted as an integer)
含义:这是导致事务失败的真正原因。
场景:你的代码正在执行一个 INSERT INTO audit_issues ... 语句。
具体问题:SQL 语句中的第 68 个参数($68)期望是一个 整数(integer),但你传入的却是一个 字符串 'c5fc'。
推断:'c5fc' 看起来像是一个十六进制字符串或者某种短 ID/哈希值。你的数据库模型(Model)中,某个字段定义为 Integer 类型,但你在赋值时传入了这个字符串。
可能的出错字段
根据 INSERT INTO audit_issues 的字段列表:
(id, task_id, file_path, line_number, column_number, issue_type, severity, title, message, description, suggestion, code_snippet, ai_explanation, status, resolved_by, resolved_at)
最可能出错的字段是:
line_number (行号):通常是整数。如果代码解析器误将某个十六进制偏移量或哈希片段当成了行号。
column_number (列号):通常是整数。
severity (严重程度):如果你用整数枚举(如 1=Low, 2=High)存储,但传入了字符串。
status:同上,如果是整数枚举。
id:虽然通常是 UUID (VARCHAR),但如果你的主键设计是自增整数或特定格式的整数 ID,也可能出错。但看 SQL 中 $1::VARCHAR,ID 似乎是字符串,所以 ID 的可能性较小。
高度怀疑对象:line_number 或 column_number。因为 'c5fc' 这种值很像是在解析代码位置时,错误地提取了内存地址、哈希值的一部分,或者是十六进制表示的行号没有被转换成十进制整数。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with app/api/v1/endpoints/scan.py around process_zip_task line 221, then inspect the audit_issues model and the values inserted during scanning. Reproduce the PostgreSQL type error and trace the value 'c5fc' to its source. Done should include successful insertion and reliable scan continuation, with the requested same-model, same-prompt AI results reused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, postgresql, python, sqlalchemy
- Domain
- ai, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100