Bug 31441 - Koha::Item::as_marc_field ignores subfields where kohafield is an empty string
Summary: Koha::Item::as_marc_field ignores subfields where kohafield is an empty string
Status: Passed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Julian Maurice
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-23 12:21 UTC by Julian Maurice
Modified: 2022-09-30 08:20 UTC (History)
2 users (show)

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


Attachments
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = '' (3.77 KB, patch)
2022-08-23 12:23 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = '' (3.81 KB, patch)
2022-09-22 23:25 UTC, David Nind
Details | Diff | Splinter Review
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = '' (3.91 KB, patch)
2022-09-30 08:17 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Maurice 2022-08-23 12:21:47 UTC
marc_subfield_structure.kohafield can be NULL, but it can also be an empty string. But in that case, Koha::Item::as_marc_field ignores them, which means the resulting MARC::Field object has missing data.  This can produce a bug in OPAC ISBD view (and probably other places where this method is used)
Comment 1 Julian Maurice 2022-08-23 12:23:32 UTC
Created attachment 139676 [details] [review]
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = ''

marc_subfield_structure.kohafield can be NULL, but it can also be an
empty string. But in that case, Koha::Item::as_marc_field ignores them,
which means the resulting MARC::Field object has missing data.
This can produce a bug in OPAC ISBD view (and probably other places
where this method is used)

Test plan:
1. Edit the default biblio MARC framework for the item field: find or
   create a subfield that is not linked to a DB column.
   Save even if you made no changes to make sure that
   marc_subfield_structure.kohafield is set to an empty string.
   I'll use 995$Z as an example for the following steps.
2. Add the following to syspref OPACISBD:
    #995|<br>Item:|{995Z}|
3. Create a biblio with an item and put a value into 995$Z
4. Go to the ISBD detail page for this record at OPAC. Confirm that the
   value you entered in 995$Z is not visible
5. Apply patch and restart koha
6. Refresh the ISBD detail page. Confirm that the 995$Z is now visible.
7. Run `prove t/db_dependent/Koha/Item.t`
Comment 2 David Nind 2022-09-22 23:25:04 UTC
Created attachment 140877 [details] [review]
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = ''

marc_subfield_structure.kohafield can be NULL, but it can also be an
empty string. But in that case, Koha::Item::as_marc_field ignores them,
which means the resulting MARC::Field object has missing data.
This can produce a bug in OPAC ISBD view (and probably other places
where this method is used)

Test plan:
1. Edit the default biblio MARC framework for the item field: find or
   create a subfield that is not linked to a DB column.
   Save even if you made no changes to make sure that
   marc_subfield_structure.kohafield is set to an empty string.
   I'll use 995$Z as an example for the following steps.
2. Add the following to syspref OPACISBD:
    #995|<br>Item:|{995Z}|
3. Create a biblio with an item and put a value into 995$Z
4. Go to the ISBD detail page for this record at OPAC. Confirm that the
   value you entered in 995$Z is not visible
5. Apply patch and restart koha
6. Refresh the ISBD detail page. Confirm that the 995$Z is now visible.
7. Run `prove t/db_dependent/Koha/Item.t`

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2022-09-23 00:30:43 UTC
Testing notes using a MARC21 instance (using koha-testing-docker):

1. I edited an existing subfield 995$z for the BKS framework, and made visible in the OPAC, staff interface, and editor

2. I also created a new subfield 995$Z for the BKS framework, and made visible in the OPAC, staff interface, and editor

3. Initially, everything worked as expected as per the test plan: not displayed in OPAC before the patch was applied. Only tested for OPAC ISBD display.

4. Then I retested again after I signed off just to check the staff interface, and it was displayed correctly without applying the patch on master (flush_memcached, restart_all, cleared browser cache - I also shut down KTD and restarted again, still the same behaviour).

5. I also added the display of the field to the staff interface (ISBD system preference).

Has this been fixed some other way, or have I totally screwed up caching/my git clone/testing? Or is it UNIMARC specific?
Comment 4 Marcel de Rooy 2022-09-30 08:17:48 UTC
Created attachment 141111 [details] [review]
Bug 31441: Fix Koha::Item::as_marc_field when kohafield = ''

marc_subfield_structure.kohafield can be NULL, but it can also be an
empty string. But in that case, Koha::Item::as_marc_field ignores them,
which means the resulting MARC::Field object has missing data.
This can produce a bug in OPAC ISBD view (and probably other places
where this method is used)

Test plan:
1. Edit the default biblio MARC framework for the item field: find or
   create a subfield that is not linked to a DB column.
   Save even if you made no changes to make sure that
   marc_subfield_structure.kohafield is set to an empty string.
   I'll use 995$Z as an example for the following steps.
2. Add the following to syspref OPACISBD:
    #995|<br>Item:|{995Z}|
3. Create a biblio with an item and put a value into 995$Z
4. Go to the ISBD detail page for this record at OPAC. Confirm that the
   value you entered in 995$Z is not visible
5. Apply patch and restart koha
6. Refresh the ISBD detail page. Confirm that the 995$Z is now visible.
7. Run `prove t/db_dependent/Koha/Item.t`

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 5 Marcel de Rooy 2022-09-30 08:20:53 UTC
(In reply to David Nind from comment #3)
> Has this been fixed some other way, or have I totally screwed up caching/my
> git clone/testing? Or is it UNIMARC specific?

Koha/Filter/MARC/EmbedItems.pm:        push @item_fields, $item->as_marc_field( { mss => $mss } );

opac/opac-ISBDdetail.pl:    {   filters => [ 'EmbedItems', 'ViewPolicy' ],


Use of as_marc_field is not very widespread. catalogue/ISBDdetail.pl does not use it.