Skip to content

Fix nil @submission in OntologyProcessor when metadata extraction bails#283

Open
alexskr wants to merge 2 commits into
developfrom
fix/nil-submission-in-notify
Open

Fix nil @submission in OntologyProcessor when metadata extraction bails#283
alexskr wants to merge 2 commits into
developfrom
fix/nil-submission-in-notify

Conversation

@alexskr

@alexskr alexskr commented Apr 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds the missing regression test for the misleading log line seen on ncbo_cron:

Email sending failed: undefined method `archived?' for nil:NilClass
  ontologies_linked_data/lib/ontologies_linked_data/services/submission_process/submission_processor.rb:73

That error was a symptom — the real failure was upstream in metadata extraction.

Root cause

  • SubmissionMetadataExtractor#extract_metadata uses a bare return on the unless @submission.valid? branch, so it returns nil for invalid submissions.
  • OntologyProcessor#process_submission does @submission = @submission.extract_metadata(...), overwriting its own submission reference with that nil.
  • Subsequent @submission.* calls then failed. In the ensure block, notify_submission_processed invoked @submission.archived? on nil, and its inner rescue logged the misleading "Email sending failed: ..." line.

Status

The underlying bug was already fixed on develop by f0867418 ("Guard against nil submission after metadata extraction failure"), which merged via #294:

  • process_submission raises a clear StandardError ("Submission processing aborted: extract_metadata returned nil …") instead of silently continuing on a nil submission.
  • notify_submission_processed guards return 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

  • New test/services/test_submission_processor.rb reproducing the exact path. It stubs extract_metadata to return nil and asserts:
    1. process_submission aborts with a clean StandardError (not a NoMethodError on nil.archived?), and
    2. notify_submission_processed never logs the misleading "Email sending failed" line.

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.
@alexskr alexskr marked this pull request as draft April 23, 2026 06:21
@alexskr alexskr requested a review from mdorf April 23, 2026 06:31
@alexskr alexskr marked this pull request as ready for review April 23, 2026 06:32
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

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.76%. Comparing base (752e7df) to head (dba4027).

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     
Flag Coverage Δ
ag 80.64% <ø> (-0.02%) ⬇️
fs 80.74% <ø> (+0.02%) ⬆️
gd 80.66% <ø> (-0.02%) ⬇️
unittests 80.76% <ø> (+0.01%) ⬆️
vo 80.67% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant