[BUG] Unhandled AttributeError on empty database queries for GeneralData and CCExtractorVersion
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 31
- Forks
- 92
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 29
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from CCExtractor/sample-platform
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
CCExtractor/sample-platform#1273 · 1 comment ·
Maintainers usually reply within 4 days
-
[BUG] `TypeError: 'ContentFile' object is not subscriptable` in mod_upload when creating GitHub issuePossibly taken @garv-sanveria claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 30/100
CCExtractor/sample-platform#1261 ·
Maintainers usually reply within 4 days
-
[BUG] Missing timeouts on 5 outbound HTTP calls outside mod_ci (follow-up to #943)Possibly taken @devnishantt claimed this 54 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 84/100
CCExtractor/sample-platform#1192 · 2 comments ·
Maintainers usually reply within 4 days
-
[Feature Request] Improve comparison algorithm to handle frame offsets intelligently (GSoC Qualification)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
CCExtractor/sample-platform#1079 ·
Maintainers usually reply within 4 days
-
[BUG] never-worked baseline handling is not fully integrated into trusted CI reportingMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 42/100
CCExtractor/sample-platform#1057 · 2 comments ·
Maintainers usually reply within 4 days
All issues in CCExtractor/sample-platform
Similar issues
-
CI: pin OS images in build/publish tests instead of `*-latest`Possibly taken @shikhabhadoria claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
vacanza/holidays#4220 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
open-webui/open-webui#34817 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
can4hou6joeng4/boss-agent-cli#2552 ·
Maintainers usually reply within 1 day
-
bench: agent-kanban-smoke accepts the session route's own live fleet read, not only a delegated resultPossibly taken @bnaylor claimed this today. Openneeds-triage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
gke-labs/kube-agents#6860 ·
Maintainers usually reply within 1 day
-
documentation good first issue priority: low
Difficulty 1/5 Under an hour Newbie friendliness 85/100
fukubie/StockLlama#57 ·