Fix nil @submission in OntologyProcessor when metadata extraction bails#283
Open
alexskr wants to merge 2 commits into
Open
Fix nil @submission in OntologyProcessor when metadata extraction bails#283alexskr wants to merge 2 commits into
alexskr wants to merge 2 commits into
Conversation
SubmissionMetadataExtractor#extract_metadata used a bare `return` when the submission failed validation, returning nil. OntologyProcessor assigned that nil back over its own @submission, so the ensure-block call to notify_submission_processed raised NoMethodError on nil.archived? -- which its inner rescue logged as the misleading "Email sending failed: undefined method `archived?' for nil:NilClass". - submission_extract_metadata.rb: return @submission on the invalid path so the method has a consistent return value. - submission_processor.rb: stop reassigning @submission from the extract_metadata return value; the extractor mutates the shared instance in place via @submission.save. - submission_processor.rb: guard notify_submission_processed against a nil @submission so a missing submission can't surface as the misleading "Email sending failed" log line. - Add regression test reproducing the full path.
develop already fixed the nil-@submission bug (extract_metadata returns nil on an invalid submission -> processor aborts with a clear StandardError, plus a nil guard in notify_submission_processed). Resolve the conflict by taking develop's processor and extractor verbatim and reverting this branch's superseded `return @submission` change, which would have turned develop's `if @submission.nil?` abort into dead code. Keep this branch's unique contribution -- the regression test -- adapted to develop's abort semantics: it now asserts the processor raises a clean StandardError (not a NoMethodError on nil) and that the misleading "Email sending failed" line never appears.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #283 +/- ##
===========================================
+ Coverage 80.74% 80.76% +0.01%
===========================================
Files 100 100
Lines 6774 6774
===========================================
+ Hits 5470 5471 +1
+ Misses 1304 1303 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Adds the missing regression test for the misleading log line seen on
ncbo_cron:That error was a symptom — the real failure was upstream in metadata extraction.
Root cause
SubmissionMetadataExtractor#extract_metadatauses a barereturnon theunless @submission.valid?branch, so it returnsnilfor invalid submissions.OntologyProcessor#process_submissiondoes@submission = @submission.extract_metadata(...), overwriting its own submission reference with thatnil.@submission.*calls then failed. In theensureblock,notify_submission_processedinvoked@submission.archived?onnil, and its innerrescuelogged the misleading"Email sending failed: ..."line.Status
The underlying bug was already fixed on
developby f0867418 ("Guard against nil submission after metadata extraction failure"), which merged via #294:process_submissionraises a clearStandardError("Submission processing aborted: extract_metadata returned nil …") instead of silently continuing on anilsubmission.notify_submission_processedguardsreturn if @submission.nil? || @submission.archived?, so a missing submission can no longer surface as the misleading log line.This branch's original code changes are therefore superseded and were dropped during the merge with
develop. What remains — and what this PR now contributes — is the regression test that f086741 did not include.Changes
test/services/test_submission_processor.rbreproducing the exact path. It stubsextract_metadatato returnniland asserts:process_submissionaborts with a cleanStandardError(not aNoMethodErroronnil.archived?), andnotify_submission_processednever logs the misleading"Email sending failed"line.