Bug 30691 - ElasticSearch Indexer crashes on authtypecode NAME_EVENT
Summary: ElasticSearch Indexer crashes on authtypecode NAME_EVENT
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching - Elasticsearch (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Thomas Klausner
QA Contact:
URL:
Keywords:
Depends on: 21958
Blocks:
  Show dependency treegraph
 
Reported: 2022-05-05 12:57 UTC by Thomas Klausner
Modified: 2023-06-19 22:14 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Skip unknown authtypes instead of dying (3.97 KB, patch)
2022-05-05 13:18 UTC, Thomas Klausner
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Klausner 2022-05-05 12:57:20 UTC
When GuessAuthTypeCode encounters a record containing tag 147, it returns 'NAME_EVENT'. But in the default Koha installation, 'NAME_EVENT' is not registered in auth_types:

select * from auth_types where authtypecode = 'NAME_EVENT';
Empty set (0.000 sec)

This causes a bug in Koha/SearchEngine/Elasticsearch.pm:362, because $field is undefined and then passed on to C4::Heading->new_from_field, which dies:
Can't call method "tag" on an undefined value at /usr/share/koha/lib/C4/Heading.pm line 71

A simple fix (will be provided soon) is to just ignore and report such cases (as done a few lines further down in Koha/SearchEngine/Elasticsearch.pm, when there is no $authtypecode.
Comment 1 Thomas Klausner 2022-05-05 13:18:09 UTC
Created attachment 134639 [details] [review]
Skip unknown authtypes instead of dying

Fixes the bug...
Comment 2 Thomas Klausner 2022-05-05 13:18:57 UTC
Test Plan:

* Confirm that you do not have an authtype 'NAME_EVENT' (either in the
  DB or /cgi-bin/koha/admin/authtypes.pl
* Enable ElasticSearch
* Create or edit an authoritiy record of type 'MEETI_NAME', make sure
  that 111 is empty, and 147 has some content (you might even need to
  fiddle with the frameworks to show the 147 form in the editor)
* Note the ID of the auth record
* Run the ES indexer, limited on the auth id:
  bin/search_tools/rebuild_elasticsearch.pl -a -v -ai $YOUR_AUTH_ID
* The script will die with a message like:

  [2374] Committing final records...
  Use of uninitialized value $tag in hash element at /usr/share/perl5/MARC/Record.pm line 202.
  Use of uninitialized value $tag in regexp compilation at /usr/share/perl5/MARC/Record.pm line 206.
  Use of uninitialized value $tag in hash element at /usr/share/perl5/MARC/Record.pm line 207.
  Can't call method "tag" on an undefined value at /usr/share/koha/lib/C4/Heading.pm line 71.

Now apply the patch.

* Run ES indexer again
* It should now report something like

  [2374] Committing final records...
  Cannot handle authority type NAME_EVENT for record: 1046314. It seems like this authority type is not defined in your instance at /usr/share/koha/lib/Koha/SearchEngine/Elasticsearch.pm line 566.
  [2374] Total 1 records indexed

Sponsored-by: Steiermärkische Landesbibliothek
Comment 3 Phil Ringnalda 2023-03-04 22:02:40 UTC
Test plan can't go in that order, because GuessAuthTypeCode runs and we throw when you save the authority record. So it has to be

* Leave SearchEngine set to Zebra
* Edit MEETI_NAME framework, uncheck Mandatory for tag 111
* Create authority with 147 and no 111
* Switch SearchEngine to ElasticSearch, reindex

Seems like a bug that we include 147 in every authtype framework, since having two 1xx headings in an authority record is both invalid and not going to work, and you have to go to a lot of trouble to make the one that should be mandatory for that authtype not mandatory to have the 147 even pretend to do something.

But since 147 and 162 exist, but are too obscure to be worth shipping an authtype framework for them, this seems like a reasonable solution if people do the wrong thing trying to use them.

The patch doesn't work, though, since some stray whitespace crept into 
"->as     _string."
Comment 4 Katrin Fischer 2023-06-18 10:29:57 UTC
Should this be Needs Signoff?
Comment 5 Phil Ringnalda 2023-06-19 22:14:05 UTC
No, since "The patch doesn't work, though, since some stray whitespace crept into 
"->as     _string.""