[FIX]: Fix get_test_results() lazy-load crashes and missing-result guard#1118
Open
x15sr71 wants to merge 4 commits into
Open
[FIX]: Fix get_test_results() lazy-load crashes and missing-result guard#1118x15sr71 wants to merge 4 commits into
x15sr71 wants to merge 4 commits into
Conversation
|
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.



Pleaxse prefix your pull request with one of the following: [FEATURE] [FIX] [IMPROVEMENT].
In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
Description
get_test_results() — Production Bug Report & Fix
get_test_results()crashes with HTTP 500 on test detail pages. Productionaccess.logcontains 3,087 HTTP 500 responses on/test/URLs.error.logcontains 5697 stack-trace frames involving SQLAlchemy lazy-loading, plus 57 confirmed AttributeError crashes from a missing null check.Evidence — commands run on production VM
All commands run on the production VM at
/var/www/sample-platform/.5697 SQLAlchemy lazy-load stack-trace frames
Bug 1 stack trace (
category.regression_tests)57 NoneType crashes (Bug 3)
Bug 3 stack trace with test IDs
3087 confirmed HTTP 500 responses on test detail pages
Bug 4 — 19 regression tests with non-zero
expected_rcBug 1 — Lazy-load crash on
category.regression_tests(line 76)Stack trace appearing thousands of times in
logs/error.log(verified withgrep -A 10 "line 76, in <listcomp>"):Cause:
Category.regression_testsuses SQLAlchemy's defaultlazy='select'(no explicitlazy=inmod_regression/models.pyline 38). The lazySELECTfires inside the list comprehension when SQLAlchemy attempts a lazy load outside a usable session context.Fix:
selectinload(Category.regression_tests)on theCategoryquery loads all regression tests in one batched query within the active session.Bug 2 — Lazy-load on
regression_test_output.multiple_files(lines 93–94)result_file.regression_test_outputand.multiple_filesare both lazy-loaded relationships (mod_regression/models.pylines 148 and 153). They are accessed inside the same list comprehension that triggers Bug 1, making them structurally identical failure points in the same session context. A separately isolated stack trace for this specific relationship was not extracted from logs during this investigation.Fix:
joinedload(TestResultFile.regression_test_output).selectinload(RegressionTestOutput.multiple_files)applied to theTestResultFilequery —joinedloadfor the scalar relationship (uselist=False),selectinloadfor the collection hanging off it.Bug 3 —
result is Nonecrash (line 94)57 confirmed occurrences in
error.logatcontrollers.pyline 94:Three example occurrences with test IDs:
Cause:
TestResultFilerows are created byequality_type_requestandTestResultrows byfinish_type_request— separate HTTP calls from the VM. When aTestResultFileexists withgot IS NOT NULLbut noTestResultrow was written,resultisNoneand.exit_coderaisesAttributeError.Fix:
(result is None or result.exit_code == 0)— treats a missing result as worth checking for file mismatches rather than crashing. If the hash matches an accepted variant inmultiple_files, it clears correctly even whenresult is None.Bug 4 — File comparison skipped for non-zero expected_rc tests (line 91)
19 confirmed affected tests (
SELECT COUNT(*) FROM regression_test WHERE expected_rc != 0= 19, allexpected_rc = 10).Cause:
result.exit_code == 0skips the multiple-file variant check for any test whereexpected_rc != 0. All 19 affected tests haveregression_test_outputrows with definedcorrecthashes — proving comparison was always intended. The outer guardresult_file.got is not Nonealready ensures this block only runs when a mismatch was uploaded; the== 0check was an undocumented additional gate with no semantic justification.Fix:
result.exit_code == result.expected_rc— runs the file check whenever the exit code matched expectation, zero or non-zero. Zero behavior change for all tests whereexpected_rc = 0.Test update —
test_data_for_testCategoryis mocked in the existing test. Our change inserted.options(...)before.filter(...)in the query chain, makingmock_category.query.filter.assert_called_once()invalid —.filter()is now called on the return value of.options(), not directly on.query. The assertion is updated tomock_category.query.options.assert_called_once()to reflect the new call chain.selectinloadis also patched to prevent SQLAlchemy from rejectingMagicMockattributes when validating loader options in newer versions. No business logic or expected behavior changed.Impact
category.regression_tests)selectinload)No behavior change for any test where data is complete.