Bug 37269

Summary: Saving edits to a patron - error message clears or resets some fields
Product: Koha Reporter: David Nind <david>
Component: PatronsAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: major    
Priority: P1 - high CC: emmi.takkinen, gmcharlt, kyle.m.hall
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description David Nind 2024-07-07 09:06:10 UTC
When there is an error saving edits to a patron, some of the changes you make are cleared or reset to the previous value.

Changes noted for the patron field (by section):
- Patron identity: Surname reset - all other fields retain the changed values
- Patron guarantor: retains values
- Non-patron guarantor: Guarantor surname, Guarantor first name reset - all other fields retain the changed values (Relationship)
- Main address: all fields reset
- Contact information: all fields reset
- Alternative address: all fields reset
- Alternate contact: all fields reset
- Library management: none - all keep the changed values
- Library setup: none - all keep the changed values
- OPAC/Staff interface login: none - all keep the changed values (not sure about the password)
- Patron account flags: none - all keep the changed values
- Patron restrictions: none - all keep the changed values
- Additional attributes and identifiers: none - all keep the changed values
- Patron messaging preferences: all fields reset (but that may be more to do with changing the patron category)

To replicate:
1. Go to a patron record and edit it (I used Mary Burton).
2. Duplicate the tab so you can compare the differences.
3. Make changes to every field available. Changes I made:
   . Text fields: Put an 'A' in front of every existing text value or for any empty text field
   . For email address: me@example.com
   . For dropdown lists, selectors, or tick boxes, change to another value
   . For dates, change the year
4. Change a field so that it will generate an error in the info box area when you go to save. I could generate an error message by:
   . Changing the date of birth so that the age doesn't match the age range for the patron category - for Mary, change date of birth year to 2010
   . Change the patron category so that their age is incorrect for the patron category - for Mary, change from patron to Board
   (I'm sure there are other ways to generate an error message.)
5. When you save the form, you get an error message (I changed the patron category for Mary from Patron to Board):
     The following fields are wrong. Please fix them.
     . Patron's age is incorrect for their category. Ages allowed are 5-17.
6. Note that:
   . Some fields remain the same
   . Many fields are reset to the value they had before making the changes (empty or original values)

The issue was identified when testing Bug 31354 - Clarify options for 'Change messaging preferences to default for this category?' popup.
Comment 1 Emmi Takkinen 2025-05-27 08:30:26 UTC
This seems to happen with fields that receive their value from patron object. In surname field we have value="[% patron.surname | html %]", but in firstname field its value="[% borrower_data.firstname | html UNLESS op == 'duplicate' %]".
If I change surname field value attribute as value="[% borrower_data.surname | html %]", value retains.
Comment 2 Emmi Takkinen 2025-05-27 09:49:42 UTC
This is a tricky one. Template_param patron is used to fill out specific fields with "Add guarantee" functionality (controlled by PrefillGuaranteeField syspref). If we replace it with borrower_data, we lose ability to prefill inputs with guarantors info. I'm not sure why patron param uses %newdata instead of %data and if changing it will break something. Should test.
Comment 3 Emmi Takkinen 2025-05-27 09:57:46 UTC
(In reply to Emmi Takkinen from comment #2)
> This is a tricky one. Template_param patron is used to fill out specific
> fields with "Add guarantee" functionality (controlled by
> PrefillGuaranteeField syspref). If we replace it with borrower_data, we lose
> ability to prefill inputs with guarantors info. I'm not sure why patron
> param uses %newdata instead of %data and if changing it will break
> something. Should test.

Tested, changing %newdata as %data also breaks "Add guarantee" :D