fix: do not cache empty Achilles drilldown results on SQL failure (fixes #2208) - #2549
Open
developer-rpai wants to merge 1 commit into
Open
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
OHDSI#2208) CDMResultsAnalysisRunner.getDrilldown() caught Exception, logged it and returned the (possibly empty) ObjectNode. The @AchillesCache aspect on CDMResultsService.getDrilldown then persisted that empty report, and users saw empty drilldown reports with no way to re-trigger the query short of manually deleting the cache record. Propagate the failure instead: the aspect does not cache thrown results (it would still cache a null), the batch cache-warmer fails honestly, and the REST endpoint returns an error rather than a cacheable empty 200. Adds CDMResultsAnalysisRunnerTest regression test.
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.
Bug (fixes #2208)
A SQL failure during an Achilles drilldown produced an empty report that was persisted in the CDM cache, with no way for users to re-trigger the query short of manually deleting the cache record.
Root cause
src/main/java/org/ohdsi/webapi/report/CDMResultsAnalysisRunner.java:284-292—getDrilldown()caughtException, logged it, and returned the (possibly empty)ObjectNode.src/main/java/org/ohdsi/webapi/service/CDMResultsService.java:416-431—getDrilldownis annotated@AchillesCache(DRILLDOWN)and returns whatever the query runner produced.@Aroundadvice insrc/main/java/org/ohdsi/webapi/achilles/aspect/AchillesCacheAspect.java:43-62caches whateverjoinPoint.proceed()returns, so the empty node was written into theachilles_cachetable on first failure and served forever after.Fix
Throw instead of swallowing:
getDrilldown()now wraps the failure in aRuntimeException(with the original exception as cause) after logging. I checked the aspect semantics before choosing this direction — returningnullwould not have worked, becauseAchillesCacheService.createCache()(src/main/java/org/ohdsi/webapi/achilles/service/AchillesCacheService.java:60-74) serializes the result withobjectMapper.writeValueAsString(result), so anullwould be persisted as"null". With the throw:createCacheis skipped on failure (the exception bypasses it), so nothing is cached;AchillesCacheTasklet.execute, which already declaresthrows Exception) fails honestly instead of writing empty drilldown rows;Tests
Added
src/test/java/org/ohdsi/webapi/report/CDMResultsAnalysisRunnerTest.java:getDrilldown_propagatesQueryFailureInsteadOfReturningEmptyResultmocksJdbcTemplateto throw onquery()and asserts the failure propagates with the SQL exception as cause. On the pristine code this test fails (emptyObjectNodereturned,fail()fires); on the fixed code it passes.Honest test note: I could not run the test suite locally — this sandbox cannot reach Maven repositories (no network route to
repo.ohdsi.org/Maven Central, and no local~/.m2cache), somvn compilefails at dependency resolution before any test runs. Please let CI (mavenbuild) executeCDMResultsAnalysisRunnerTestbefore merging. The fix itself is a minimal, signature-preserving change (no caller modifications needed).Fixes #2208.