[BUG] Unhandled AttributeError on empty database queries for GeneralData and CCExtractorVersion

Đang mở
#1,275 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@Aspirant200715 đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #1276 của @Aspirant200715 — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Sample platform commit:

ce8539dab74eb7dbc868b89d18060da258ec3ce9

Contributor Checklist

In raising this issue, I confirm the following:

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 the last_commit database 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 raise TestNotFoundException when no commit entry exists, allowing the application to render the appropriate 404 response instead of returning HTTP 500.
Proposed Solution
  1. Add appropriate None checks around .first() query results in:

    • mod_home/controllers.py
    • mod_sample/controllers.py
    • mod_test/controllers.py
  2. Skip downstream Test.query lookups in mod_sample/controllers.py whenever the corresponding commit hashes are None.

  3. Raise TestNotFoundException in mod_test/controllers.py when no platform-specific commit entry exists.

  4. Add unit tests covering unseeded database scenarios in:

    • tests/test_home/test_controllers.py
    • tests/test_sample/test_controllers.py
    • tests/test_test/test_controllers.py

I have implemented a fix along with the corresponding unit tests and am preparing to submit a PR.

Ngôn ngữ chính
Python
Star
31
Fork
92
Merge trung bình
4 ngày 9 giờ
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CCExtractor/sample-platform

Tất cả issue của CCExtractor/sample-platform

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.