[Bug 43710] New: OPAC self-registration crashes with 500 if an attribute type is mandatory+opac_editable but not opac_mandatory
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Bug ID: 43710 Summary: OPAC self-registration crashes with 500 if an attribute type is mandatory+opac_editable but not opac_mandatory Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: OPAC Assignee: oleonard@myacpl.org Reporter: adolfo.rodriguez@xercode.es QA Contact: testopia@bugs.koha-community.org Target Milestone: --- If a patron attribute type is configured with mandatory=1 and opac_editable=1 but opac_mandatory=0, OPAC self-registration crashes with an uncaught-exception 500 instead of completing. Root cause: opac/opac-memberentry.pl's own CheckMandatoryAttributes() only checks the opac_mandatory flag to decide which fields to require on the registration form. But Koha::Patron->extended_attributes()'s internal mandatory check (Koha/Patron.pm, ~line 2884) uses mandatory + opac_editable instead, and ignores opac_mandatory entirely: if ( $interface eq 'opac' ) { $params->{opac_editable} = 1; } my @required_attribute_types = Koha::Patron::Attribute::Types->search( $params, ... )->get_column('code'); So a type with mandatory=1, opac_editable=1, opac_mandatory=0 is never required by the OPAC form, but IS required by extended_attributes()'s own check. If the patron leaves it blank, Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute is thrown at opac/opac-memberentry.pl's call to $patron->extended_attributes($attributes), which is not caught, and the request dies with a 500. By that point the Koha::Patron row has already been created and stored (a few lines earlier); only the extended-attributes save fails, and that save is wrapped in a DBIx::Class txn_do, so the failure rolls back cleanly with no partially-saved attributes. The account itself is valid — only the attribute type configuration is inconsistent. Steps to reproduce: 1. Administration > Patron attribute types: create or edit a type with Mandatory checked, OPAC editable checked, OPAC mandatory NOT checked. 2. With PatronSelfRegistrationVerifyByEmail disabled, register a new patron via the OPAC self-registration form, leaving that attribute blank. 3. The request crashes with an uncaught-exception 500 instead of completing registration. Proposed fix: wrap the $patron->extended_attributes($attributes) call in opac-memberentry.pl in a try/catch. On Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute specifically, log a warning identifying the misconfigured attribute type and let registration complete normally (the account is already valid) instead of crashing. Other exception types are re-thrown unchanged. Note: an earlier internal write-up of this issue assumed the OPAC form and extended_attributes() disagreed on mandatory+opac_editable directly, but current main already guards that combination via the opac_editable filter above — the actual remaining gap is specifically the opac_mandatory vs mandatory+opac_editable mismatch described here. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #1 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 207221 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=207221&action=edit OPAC self-registration crashes with 500 if an attribute type is mandatory+opac_editable but not opac_mandatory -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Owen Leonard <oleonard@myacpl.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|oleonard@myacpl.org |adolfo.rodriguez@xercode.es -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Failed QA CC| |david@davidnind.com --- Comment #2 from David Nind <david@davidnind.com> --- I could not reproduce on main. For me, the self-registration form successfully submits without an error. Testing notes (using KTD): 1. Note: For the patron attribute type created, Mandatory = Staff interface mandatory (label on the form) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #3 from David Nind <david@davidnind.com> --- Created attachment 208909 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208909&action=edit Bug 43710: OPAC self-registration: catch MissingMandatoryExtendedAttribute instead of crashing with a 500 If a patron attribute type is configured with mandatory=1 and opac_editable=1 but opac_mandatory=0, the OPAC self-registration form (opac-memberentry.pl) never requires it from the patron (its own CheckMandatoryAttributes only checks opac_mandatory), but Koha::Patron->extended_attributes()'s internal mandatory check uses mandatory + opac_editable, ignoring opac_mandatory entirely. If the patron leaves that field blank, extended_attributes() throws Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute, which was not caught here, producing an uncaught-exception 500. By the time this call runs, the Koha::Patron row has already been created and stored; the exception only affects saving extended attributes, and that save is wrapped in a DBIx::Class txn_do, so a failure rolls back cleanly (no partially-saved attributes). Since the account itself is valid, abort the attribute save on this specific misconfiguration, log a warning for library staff, and let registration complete normally rather than failing the whole request. Other exception types are re-thrown unchanged. Steps to follow: 1. Administration > Patron attribute types: create (or edit) an attribute type with Mandatory checked, OPAC editable checked, and OPAC mandatory NOT checked. 2. Register a new patron via the OPAC self-registration form (with PatronSelfRegistrationVerifyByEmail disabled), leaving that attribute blank. Confirm the registration crashes with an uncaught-exception 500 — bug confirmed. 3. Apply this patch and restart Plack if running under it. 4. Repeat step 2. Confirm registration completes normally (the "Registration complete" page is shown) instead of a 500, and check the Plack/error log for the new warning identifying the misconfigured attribute type. 5. Edit the attribute type to also check OPAC mandatory, repeat registration with the field filled in, and confirm it saves correctly — no regression for the normal case. Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #207221|0 |1 is obsolete| | --- Comment #4 from David Nind <david@davidnind.com> --- Comment on attachment 207221 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=207221 OPAC self-registration crashes with 500 if an attribute type is mandatory+opac_editable but not opac_mandatory I reattached the patch using KTD (git bz attach -e 43710 HEAD) so that it is shown as expected in Bugzilla, along with the test plan. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|OPAC self-registration |OPAC self-registration |crashes with 500 if an |crashes with a 500 error |attribute type is |when |mandatory+opac_editable but |ExtendedPatronAttributes is |not opac_mandatory |disabled and a patron | |attribute type is mandatory -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #208909|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #5 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 208954 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208954&action=edit Bug 43710: Check ExtendedPatronAttributes before saving self-registration attributes When ExtendedPatronAttributes is disabled, the OPAC self-registration form does not show the patron attributes, so none are submitted. But opac-memberentry.pl still called $patron->extended_attributes() with the empty list, and its check of the mandatory attribute types does not look at that preference. If a patron attribute type is mandatory and editable in the OPAC, the check throws Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute, which is not caught, and the registration ends with an error 500 (the patron has already been created at that point). When ExtendedPatronAttributes is enabled, the attribute is shown and submitted, even if empty, so the error does not happen. This patch only saves the extended attributes when ExtendedPatronAttributes is enabled, as members/memberentry.pl already does in the staff interface. Steps to follow: 1. Set the system preferences: - PatronSelfRegistration: Allow - PatronSelfRegistrationDefaultCategory: any category (for example PT) - PatronSelfRegistrationVerifyByEmail: Don't require 2. Administration > Patron attribute types: add a type with "Mandatory" and "Editable in OPAC" checked. 3. Set ExtendedPatronAttributes to "Don't enable" and restart_all (the preference is cached). 4. OPAC > Create an account: fill in the form and submit it. There is an error 500, and the log shows Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute. 5. Apply the patch and restart_all. 6. Repeat step 4: the registration is completed. 7. Set ExtendedPatronAttributes to "Enable", restart_all and register another patron: the attribute is shown in the form, and it is saved when a value is entered (check it in the patron details in the staff interface). Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #6 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Thanks for testing, David, and for reattaching the patch! You were right: with ExtendedPatronAttributes enabled it can't be reproduced, because the attribute is shown in the form and submitted (even if empty), so it counts as present. I've now reproduced it in KTD: the error only happens when ExtendedPatronAttributes is disabled. Then the form doesn't show the attributes, but opac-memberentry.pl still calls $patron->extended_attributes() with an empty list, and the check of mandatory attribute types (mandatory and editable in the OPAC) doesn't look at that preference, so it throws MissingMandatoryExtendedAttribute and the registration ends with an error 500. The new patch replaces the previous approach: it only saves the extended attributes when ExtendedPatronAttributes is enabled, as members/memberentry.pl already does in the staff interface. I've updated the bug title and the test plan. Note that the preference is cached, so restart_all is needed after changing it. Have a nice day. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #208954|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #7 from David Nind <david@davidnind.com> --- Created attachment 209234 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209234&action=edit Bug 43710: Check ExtendedPatronAttributes before saving self-registration attributes When ExtendedPatronAttributes is disabled, the OPAC self-registration form does not show the patron attributes, so none are submitted. But opac-memberentry.pl still called $patron->extended_attributes() with the empty list, and its check of the mandatory attribute types does not look at that preference. If a patron attribute type is mandatory and editable in the OPAC, the check throws Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute, which is not caught, and the registration ends with an error 500 (the patron has already been created at that point). When ExtendedPatronAttributes is enabled, the attribute is shown and submitted, even if empty, so the error does not happen. This patch only saves the extended attributes when ExtendedPatronAttributes is enabled, as members/memberentry.pl already does in the staff interface. Steps to follow: 1. Set the system preferences: - PatronSelfRegistration: Allow - PatronSelfRegistrationDefaultCategory: any category (for example PT) - PatronSelfRegistrationVerifyByEmail: Don't require 2. Administration > Patron attribute types: add a type with "Mandatory" and "Editable in OPAC" checked. 3. Set ExtendedPatronAttributes to "Don't enable" and restart_all (the preference is cached). 4. OPAC > Create an account: fill in the form and submit it. There is an error 500, and the log shows Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute. 5. Apply the patch and restart_all. 6. Repeat step 4: the registration is completed. 7. Set ExtendedPatronAttributes to "Enable", restart_all and register another patron: the attribute is shown in the form, and it is saved when a value is entered (check it in the patron details in the staff interface). Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |release-notes-needed --- Comment #8 from David Nind <david@davidnind.com> --- Thanks Adolfo for updating. Everything works as per the test plan and the bug is now signed off. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |OPAC self-registration no release notes| |longer fails with an error | |500 when | |ExtendedPatronAttributes is | |disabled and a patron | |attribute type is mandatory | |and editable in the OPAC. | |The patron attributes are | |now only saved when | |ExtendedPatronAttributes is | |enabled, as in the staff | |interface. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |lisette@bywatersolutions.co |y.org |m -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA --- Comment #9 from Lisette Scheer <lisette@bywatersolutions.com> --- A note that this only happens when the field is mandatory in the staff interface and not if it's mandatory only in the opac. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #209234|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #10 from Lisette Scheer <lisette@bywatersolutions.com> --- Created attachment 210751 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210751&action=edit Bug 43710: Check ExtendedPatronAttributes before saving self-registration attributes When ExtendedPatronAttributes is disabled, the OPAC self-registration form does not show the patron attributes, so none are submitted. But opac-memberentry.pl still called $patron->extended_attributes() with the empty list, and its check of the mandatory attribute types does not look at that preference. If a patron attribute type is mandatory and editable in the OPAC, the check throws Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute, which is not caught, and the registration ends with an error 500 (the patron has already been created at that point). When ExtendedPatronAttributes is enabled, the attribute is shown and submitted, even if empty, so the error does not happen. This patch only saves the extended attributes when ExtendedPatronAttributes is enabled, as members/memberentry.pl already does in the staff interface. Steps to follow: 1. Set the system preferences: - PatronSelfRegistration: Allow - PatronSelfRegistrationDefaultCategory: any category (for example PT) - PatronSelfRegistrationVerifyByEmail: Don't require 2. Administration > Patron attribute types: add a type with "Mandatory" and "Editable in OPAC" checked. 3. Set ExtendedPatronAttributes to "Don't enable" and restart_all (the preference is cached). 4. OPAC > Create an account: fill in the form and submit it. There is an error 500, and the log shows Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute. 5. Apply the patch and restart_all. 6. Repeat step 4: the registration is completed. 7. Set ExtendedPatronAttributes to "Enable", restart_all and register another patron: the attribute is shown in the form, and it is saved when a value is entered (check it in the patron details in the staff interface). Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)| |26.11.00 released in| | Status|Passed QA |Pushed to main -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43710 --- Comment #11 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- Thanks everyone! Pushed to main for 26.11! -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org