Skip to content

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

Open
alexskr wants to merge 1 commit intodevelopfrom
fix/nil-submission-in-notify
Open

Fix nil @submission in OntologyProcessor when metadata extraction bails#283
alexskr wants to merge 1 commit intodevelopfrom
fix/nil-submission-in-notify

Conversation

@alexskr
Copy link
Copy Markdown
Member

@alexskr alexskr commented Apr 23, 2026

Summary

Fixes the misleading log line observed on ncbo_cron when processing ontologies:

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 used a bare return on the unless @submission.valid? branch, so it returned nil for invalid submissions.
  • OntologyProcessor#process_submission did @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.

Changes

  • 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 already mutates the shared instance via @submission.save.
  • submission_processor.rb: return if @submission.nil? guard in notify_submission_processed, so a missing submission can't surface as the misleading log line again.
  • New regression test test/services/test_submission_processor.rb reproducing the exact path.

Test plan

  • New test fails on develop with NoMethodError: undefined method 'save' for nil:NilClass (confirmed by reverting the fixes locally).
  • New test passes on this branch against 4store (rake test:docker:fs).
  • Full rake test:docker:fs run on this branch before merge.

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
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