Repository navigation
[FIX] Guard .first() database queries against None to prevent AttributeError - #1276
Open
Aspirant200715 wants to merge 1 commit into
Open
Aspirant200715 wants to merge 1 commit into
Aspirant200715 wants to merge 1 commit into
Conversation
…vent AttributeError
Guard against AttributeError on empty database or unseeded GeneralData and CCExtractorVersion records.
- mod_home/controllers.py: guard last_commit query on index route
- mod_sample/controllers.py: guard last_commit and last_release queries; avoid querying Test when commit hash is None
- mod_test/controllers.py: raise TestNotFoundException in by_platform if fetch_commit entry is missing
- tests/: add unit tests for unseeded database scenarios in test_home, test_sample, and test_test
Aspirant200715
requested review from
canihavesomecoffee and
thealphadollar
as code owners
November 13, 2026 16:26
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



In raising this pull request, I confirm the following:
My familiarity with the project is as follows:
Description
Fixes #1275
This pull request prevents crashes caused by unhandled
AttributeErrorexceptions ('NoneType' object has no attribute 'value'/'commit') on routes queryingGeneralDataorCCExtractorVersionwhen running on a fresh installation or an empty/unseeded database.Root Cause
mod_home/controllers.pylast_commitquery unconditionally dereferences.first().valueonGeneralData..first()returnsNone, resulting in anAttributeError.mod_sample/controllers.pylatest_commitandlast_releasequeries unconditionally dereference.first().valueand.first().commit, respectively.AttributeError.Noneto downstream queries can trigger unnecessaryWHERE commit IS NULLdatabase lookups.mod_test/controllers.pylatest_commit_info,commit_hashunconditionally dereferences.first().valueforfetch_commit_<platform>.TestNotFoundExceptionand rendering the appropriate 404 page.Solution
mod_home/controllers.pylast_commitquery result.Noneto the template context when the entry is missing, which Jinja2 handles gracefully.mod_sample/controllers.pylatest_commit_entryandlast_release_entry.Test.query.filter()lookups execute only when the corresponding commit hashes exist.mod_test/controllers.pyfetch_commit_<platform>entry inGeneralData.test/test_not_found.htmlwith an HTTP 404 response instead of an HTTP 500 error.Unit Tests
test_root_without_general_dataintests/test_home/test_controllers.py.test_sample_info_without_commit_or_releaseintests/test_sample/test_controllers.py.test_by_platform_no_commit_hashintests/test_test/test_controllers.py.Verification
All linters and type checkers pass without issues:
pycodestylepydocstyleisortmypydodgy