[BUG] Unhandled AttributeError on empty database queries for GeneralData and CCExtractorVersion
维护者通常 4 天内回复
评估
调研方向
The crashes are in the .first().value and .first().commit lookups in mod_home/controllers.py, mod_sample/controllers.py and mod_test/controllers.py. Start by reading those three query sites and the existing tests under tests/test_home, tests/test_sample and tests/test_test. Done means the three routes no longer return HTTP 500 on an unseeded database, and the test endpoint raises TestNotFoundException. The reporter says a fix is already in progress, so check with them before starting.
由索引模型根据 Issue 内容生成。
描述
Sample platform commit:
ce8539dab74eb7dbc868b89d18060da258ec3ce9
Contributor Checklist
In raising this issue, I confirm the following:
- I have read and understood the [Contributors Guide](https://github.com/CCExtractor/sample-platform/blob/master/.github/CONTRIBUTING.md).
- I have checked that the bug fix I'm reporting can be replicated, or that the feature I'm suggesting isn't already present.
- I have checked that the issue I'm posting hasn't already been reported.
- I have checked that the issue hasn't already been solved and that no duplicates exist in [closed issues](https://github.com/CCExtractor/sample-platform/issues?q=is%3Aissue+is%3Aclosed) or [open issues](https://github.com/CCExtractor/sample-platform/issues).
- I have checked the Pull Requests tab for existing solutions or implementations related to this issue.
Familiarity with the Project
- I have never visited/used the platform.
- I have used the platform just a couple of times.
- I have used the platform extensively, but have not contributed previously.
- I am an active contributor to the platform.
Summary
When sample-platform is initialized on a fresh installation or against an empty database where GeneralData or CCExtractorVersion records have not yet been seeded, multiple endpoints crash with unhandled AttributeError exceptions:
'NoneType' object has no attribute 'value''NoneType' object has no attribute 'commit'
These exceptions result in HTTP 500 responses instead of graceful handling of missing database records.
Affected Routes & Files
1. Homepage (/)
File: mod_home/controllers.py
The following query directly accesses .value on the result of .first():
GeneralData.query.filter(
GeneralData.key == 'last_commit'
).first().value
If the last_commit entry does not exist, .first() returns None, resulting in an AttributeError.
2. Sample Details (/sample/<id>)
File: mod_sample/controllers.py
Two queries are vulnerable to the same issue:
GeneralData.query.filter(
GeneralData.key == 'last_commit'
).first().value
CCExtractorVersion.query.order_by(
CCExtractorVersion.released.desc()
).first().commit
Both queries can return None when the database hasn't been seeded.
Additionally, passing a None commit hash to Test.query.filter(Test.commit == ...) triggers unnecessary database lookups using WHERE commit IS NULL.
3. Platform Tests (/test/by_platform/<platform>)
File: mod_test/controllers.py
The following query crashes when the platform-specific commit entry is missing:
commit_hash = GeneralData.query.filter(
GeneralData.key == 'fetch_commit_' + platform.value
).first().value
Instead of raising the expected TestNotFoundException, the endpoint returns an unhandled HTTP 500 error.
Expected Behavior
- The homepage (
/) should load gracefully even when thelast_commitdatabase entry is missing. - The sample details page (
/sample/<id>) should handle missing commit information without crashing or performing unnecessary database lookups. - The platform tests endpoint (
/test/by_platform/<platform>) should raiseTestNotFoundExceptionwhen no commit entry exists, allowing the application to render the appropriate 404 response instead of returning HTTP 500.
Proposed Solution
-
Add appropriate
Nonechecks around.first()query results in:mod_home/controllers.pymod_sample/controllers.pymod_test/controllers.py
-
Skip downstream
Test.querylookups inmod_sample/controllers.pywhenever the corresponding commit hashes areNone. -
Raise
TestNotFoundExceptioninmod_test/controllers.pywhen no platform-specific commit entry exists. -
Add unit tests covering unseeded database scenarios in:
tests/test_home/test_controllers.pytests/test_sample/test_controllers.pytests/test_test/test_controllers.py
I have implemented a fix along with the corresponding unit tests and am preparing to submit a PR.
- 主要语言
- Python
- 星标
- 31
- 派生
- 92
- 平均合并
- 4 天 9 小时
- 30 天内合并 PR
- 29
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CCExtractor/sample-platform 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 72/100
CCExtractor/sample-platform#1273 · 1 条评论 ·
维护者通常 4 天内回复
-
[BUG] `TypeError: 'ContentFile' object is not subscriptable` in mod_upload when creating GitHub issue可能已有人在做 @garv-sanveria 于 16 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
CCExtractor/sample-platform#1261 ·
维护者通常 4 天内回复
-
[BUG] Missing timeouts on 5 outbound HTTP calls outside mod_ci (follow-up to #943)可能已有人在做 @devnishantt 于 54 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 84/100
CCExtractor/sample-platform#1192 · 2 条评论 ·
维护者通常 4 天内回复
-
[Feature Request] Improve comparison algorithm to handle frame offsets intelligently (GSoC Qualification)可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
CCExtractor/sample-platform#1079 ·
维护者通常 4 天内回复
-
[BUG] never-worked baseline handling is not fully integrated into trusted CI reporting可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 42/100
CCExtractor/sample-platform#1057 · 2 条评论 ·
维护者通常 4 天内回复
查看 CCExtractor/sample-platform 的全部 Issue
相似的 Issue
-
[Bug]: DoubleMLData.from_arrays checks the treatment d with force_all_x_finite instead of force_all_d_finite可能已有人在做 @leninworld 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
DoubleML/doubleml-for-py#471 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
python-pillow/Pillow#10590 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
BUG: ZarrTrace fails in init_trace for models with datetime coordinates (object dtype coord array)未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 2 天内回复