[Bug 43870] New: EDIFACT message with no BGM segment stops edi_cron.pl
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43870 Bug ID: 43870 Summary: EDIFACT message with no BGM segment stops edi_cron.pl Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Acquisitions Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Depends on: 43757 Target Milestone: --- Follow-up to bug 43757. That bug makes Koha::Edifact->new throw Koha::Exceptions::FileNotParsed for an empty transmission, a missing or unsupported UNA and an interchange containing no messages, and makes process_invoice, process_quote and process_ordrsp record the failure against the message (status 'error' plus an edifact_errors row) and carry on. A malformed message inside an otherwise valid interchange is not covered. Koha::Edifact::Message->new assumes the second segment is a BGM and that at least one segment follows the BGM and any DTM segments: my $bgm = shift @{$data_array_ref}; my $msg_function = $bgm->elem(2); ... while ( $data_array_ref->[0]->tag eq 'DTM' ) { A message with no BGM dies with: Can't call method "elem" on an undefined value. A message that ends after its BGM and DTM segments dies in the while loop in the same way. Koha::Edifact->message_array, which builds the Message objects, is called by process_invoice, process_quote and process_ordrsp outside any error handling. The exception therefore stops edi_cron.pl: the remaining messages and accounts are not processed and the message is left in status 'processing'. Proposed changes: a. Koha::Edifact::Message->new throws Koha::Exceptions::FileNotParsed ("Message has no BGM segment") when the second segment is not a BGM, and the DTM loop stops at the end of the segments. b. The exception is raised on the first call to message_array, not when the Koha::Edifact object is constructed. c. process_invoice, process_quote and process_ordrsp catch it around message_array and handle it as bug 43757 does for a failed parse: status 'error', an edifact_errors row with the reason, a log entry, and carry on with the next message. Test plan: 1. Add an INVOICE to edifact_messages (status 'new') whose raw_msg is: UNA:+.? 'UNB+UNOC:3+TEST+KOHA+200101:0000+1'UNH+1+INVOIC'UNT+1+1'UNZ+1+1' followed by a second, valid INVOICE. 2. Run misc/cronjobs/edi_cron.pl (or process_invoice on both messages). 3. Without the patch: the cron dies on the first message, which is left in status 'processing'. 4. With the patch: the first message has status 'error' with a row in edifact_errors ("Message has no BGM segment") and the second is processed. Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43757 [Bug 43757] EDIFACT parser drops syntax 4 interchanges silently and dies on a missing UNA -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43870 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 208613 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208613&action=edit Bug 43870: Flag EDIFACT messages with no BGM instead of stopping edi_cron.pl Koha::Edifact::Message->new assumes that the second segment of a message is a BGM and that a segment follows the BGM and any DTM segments. A message with no BGM died with: Can't call method "elem" on an undefined value and one that ended after its BGM and DTM segments died in the loop that collects the DTM segments. Koha::Edifact->message_array, which builds the messages, is called by process_invoice, process_quote and process_ordrsp outside any error handling, so the exception stopped edi_cron.pl: later messages and accounts were skipped and the message was left in status 'processing'. This patch: - makes Koha::Edifact::Message->new throw Koha::Exceptions::FileNotParsed ("Message has no BGM segment") when the second segment is not a BGM, and stops the DTM loop at the end of the segments - adds Koha::EDI::_edifact_messages, used by the three process_ routines around message_array, which handles that exception as an interchange that cannot be parsed: status 'error', an edifact_errors row, a log entry, and carry on with the next message. The error recording is shared with _edifact_parser through _flag_unparsable. Test plan: 1. Apply the patch, and the patches on bug 43757 it depends on 2. prove t/Edifact.t t/db_dependent/Koha/EDI.t => they pass 3. Add an INVOICE to edifact_messages (status 'new') whose raw_msg is UNA:+.? 'UNB+UNOC:3+TEST+KOHA+200101:0000+1'UNH+1+INVOIC'UNT+1+1'UNZ+1+1' followed by a second, valid INVOICE, and run misc/cronjobs/edi_cron.pl => the first message is 'error' with a row in edifact_errors ("Message has no BGM segment"), the second is processed, and the cron completes Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43870 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org