Bug 41520 - Using additional fields on ERM agreements results in an error when loading the agreements table
Summary: Using additional fields on ERM agreements results in an error when loading th...
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: ERM (show other bugs)
Version: Main
Hardware: All All
: P5 - low critical
Assignee: Martin Renvoize (ashimema)
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
Depends on: 35451
Blocks:
  Show dependency treegraph
 
Reported: 2026-01-05 12:42 UTC by Jan Kissig
Modified: 2026-01-06 14:34 UTC (History)
7 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: Unsponsored
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes the ERM agreements table, when additional fields are added for agreements. When loading the ERM agreements table, a 500 error was generated: Something went wrong when loading the table. 500: Internal Server Error Properties not allowed: record_table. Properties not allowed: record_table. Properties not allowed: record_table.
Version(s) released in:
26.05.00
Circulation function:


Attachments
Bug 41520: Add tests for extended_attributes in ERM agreements API (3.86 KB, patch)
2026-01-05 15:06 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 41520: Filter out record_table from AdditionalFieldValue API responses (2.14 KB, patch)
2026-01-05 15:06 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 41520: Add tests for extended_attributes in ERM agreements API (3.91 KB, patch)
2026-01-05 18:47 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 41520: Filter out record_table from AdditionalFieldValue API responses (2.19 KB, patch)
2026-01-05 18:47 UTC, Jan Kissig
Details | Diff | Splinter Review
Bug 41520: Add tests for extended_attributes in ERM agreements API (3.95 KB, patch)
2026-01-06 08:36 UTC, David Nind
Details | Diff | Splinter Review
Bug 41520: Filter out record_table from AdditionalFieldValue API responses (2.24 KB, patch)
2026-01-06 08:36 UTC, David Nind
Details | Diff | Splinter Review
Bug 41520: Add tests for extended_attributes in ERM agreements API (4.03 KB, patch)
2026-01-06 12:23 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 41520: Filter out record_table from AdditionalFieldValue API responses (2.31 KB, patch)
2026-01-06 12:23 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kissig 2026-01-05 12:42:31 UTC
To recreate:

a) enable ERM module in system preferences
b) create an addition field (/cgi-bin/koha/admin/additional-fields.pl) for Agreements (erm_agreements)
c) go to /cgi-bin/koha/erm/agreements and create an agreement, fill the additional field. Save and reload /cgi-bin/koha/erm/agreements
d) see browser error 'Something went wrong when loading the table.
500: Internal Server Error. 
Properties not allowed: record_table.' and error log in ktd: '==> /var/log/koha/kohadev/plack-api-error.log <==
[2026/01/05 12:39:19] [WARN] OpenAPI >>> GET api/v1/erm/agreements [{"message":"Properties not allowed: record_table.","path":"\/body\/0\/extended_attributes\/0"}]
'
Comment 1 Martin Renvoize (ashimema) 2026-01-05 15:06:48 UTC
Created attachment 190892 [details] [review]
Bug 41520: Add tests for extended_attributes in ERM agreements API

This patch adds api unit tests for the extended_attributes functionality in the
ERM agreements API to ensure that:

1. Extended attributes are correctly returned when embedded
2. The internal record_table field is not exposed via the API
3. Both single GET and list endpoints work correctly with extended_attributes

Test plan:
1. prove t/db_dependent/api/v1/erm_agreements.t
2. Verify all tests pass
Comment 2 Martin Renvoize (ashimema) 2026-01-05 15:06:50 UTC
Created attachment 190893 [details] [review]
Bug 41520: Filter out record_table from AdditionalFieldValue API responses

Bug 35451 added a record_table field to the additional_field_values
database table for performance optimization (better joins). However,
this field was not added to the OpenAPI schema, and with
additionalProperties: false, the API validator rejects responses
containing it.

Rather than adding this internal implementation detail to the public
API schema, this patch adds a custom to_api method to
Koha::AdditionalFieldValue that filters out the record_table field.

This approach:
1. Keeps the database optimization from Bug 35451
2. Prevents internal implementation details from cluttering the API
3. Maintains context that API consumers already have from parent objects
4. Fixes OpenAPI validation errors for ERM agreements, licenses, and
   packages using extended_attributes

Test plan:
1. Create an ERM agreement with additional fields/extended attributes
2. Access the agreement via the API with extended_attributes embedded
3. Verify the response includes extended_attributes but not record_table
4. Confirm no OpenAPI validation warnings in plack-api-error.log
5. prove t/db_dependent/api/v1/erm_agreements.t
6. Verify all tests pass
Comment 3 Jan Kissig 2026-01-05 18:47:01 UTC
Created attachment 190906 [details] [review]
Bug 41520: Add tests for extended_attributes in ERM agreements API

This patch adds api unit tests for the extended_attributes functionality in the
ERM agreements API to ensure that:

1. Extended attributes are correctly returned when embedded
2. The internal record_table field is not exposed via the API
3. Both single GET and list endpoints work correctly with extended_attributes

Test plan:
1. prove t/db_dependent/api/v1/erm_agreements.t
2. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Comment 4 Jan Kissig 2026-01-05 18:47:05 UTC
Created attachment 190907 [details] [review]
Bug 41520: Filter out record_table from AdditionalFieldValue API responses

Bug 35451 added a record_table field to the additional_field_values
database table for performance optimization (better joins). However,
this field was not added to the OpenAPI schema, and with
additionalProperties: false, the API validator rejects responses
containing it.

Rather than adding this internal implementation detail to the public
API schema, this patch adds a custom to_api method to
Koha::AdditionalFieldValue that filters out the record_table field.

This approach:
1. Keeps the database optimization from Bug 35451
2. Prevents internal implementation details from cluttering the API
3. Maintains context that API consumers already have from parent objects
4. Fixes OpenAPI validation errors for ERM agreements, licenses, and
   packages using extended_attributes

Test plan:
1. Create an ERM agreement with additional fields/extended attributes
2. Access the agreement via the API with extended_attributes embedded
3. Verify the response includes extended_attributes but not record_table
4. Confirm no OpenAPI validation warnings in plack-api-error.log
5. prove t/db_dependent/api/v1/erm_agreements.t
6. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Comment 5 David Nind 2026-01-05 19:09:09 UTC
Hi Jan.

You've signed off the bug, but the status is still showing as "Needs Signoff".

David
Comment 6 David Nind 2026-01-05 19:10:46 UTC
PS: I would add my sign off, so you could do the QA, but I don't know how to do steps 2 and 3 of the test plan.
Comment 7 Jan Kissig 2026-01-06 07:19:29 UTC
(In reply to David Nind from comment #6)
> PS: I would add my sign off, so you could do the QA, but I don't know how to
> do steps 2 and 3 of the test plan.

Hi David,

thanks for the status reminder, I set it to signed off now but please add yours too:

2. Access the agreement via the API with extended_attributes embedded
3. Verify the response includes extended_attributes but not record_table

For 2 and 3 you could either use an API testing tool and set 
- the URL to: /api/v1/erm/agreements
- the header to: x-koha-embed: extended_attributes

or just open the browser development tools -> network tab and reload that page: /cgi-bin/koha/erm/agreements. 
Then take a look to for the API request to /api/v1/erm/agreements (it includes some more query params here but we can ignore them) and by double clicking that request you can check for the request headers (they include x-koha-embed with the value extended_attributes) and the response payload will include an extended_attributes object. This is how its done in firefox but I guess the other browsers work alike
Hope this was understandable :)
Comment 8 David Nind 2026-01-06 08:36:32 UTC
Created attachment 190915 [details] [review]
Bug 41520: Add tests for extended_attributes in ERM agreements API

This patch adds api unit tests for the extended_attributes functionality in the
ERM agreements API to ensure that:

1. Extended attributes are correctly returned when embedded
2. The internal record_table field is not exposed via the API
3. Both single GET and list endpoints work correctly with extended_attributes

Test plan:
1. prove t/db_dependent/api/v1/erm_agreements.t
2. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Signed-off-by: David Nind <david@davidnind.com>
Comment 9 David Nind 2026-01-06 08:36:36 UTC
Created attachment 190916 [details] [review]
Bug 41520: Filter out record_table from AdditionalFieldValue API responses

Bug 35451 added a record_table field to the additional_field_values
database table for performance optimization (better joins). However,
this field was not added to the OpenAPI schema, and with
additionalProperties: false, the API validator rejects responses
containing it.

Rather than adding this internal implementation detail to the public
API schema, this patch adds a custom to_api method to
Koha::AdditionalFieldValue that filters out the record_table field.

This approach:
1. Keeps the database optimization from Bug 35451
2. Prevents internal implementation details from cluttering the API
3. Maintains context that API consumers already have from parent objects
4. Fixes OpenAPI validation errors for ERM agreements, licenses, and
   packages using extended_attributes

Test plan:
1. Create an ERM agreement with additional fields/extended attributes
2. Access the agreement via the API with extended_attributes embedded
3. Verify the response includes extended_attributes but not record_table
4. Confirm no OpenAPI validation warnings in plack-api-error.log
5. prove t/db_dependent/api/v1/erm_agreements.t
6. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Signed-off-by: David Nind <david@davidnind.com>
Comment 10 David Nind 2026-01-06 08:46:38 UTC
Thanks Jan, with your tips I managed to muddle my way through using Bruno (an open-source API client).

Managed to reproduce the error after enabling ERM, adding two additional fields for EZR > Agreements, and creating an agreement using those fields:

   Something went wrong when loading the table.
   500: Internal Server Error
   Properties not allowed: record_table.
   Properties not allowed: record_table.
   Properties not allowed: record_table.

After the patches, the tests pass and the agreements table loads in the staff interface.

Using an API client (such as Bruno) the request is completed successfully:
- GET http://127.0.0.1:8081/api/v1/erm/agreements
- Body: No body
- Headers:
  . Key: x-koha-embed
  . Value: extended_attributes
- Auth: Basic Auth with koha + koha
Comment 11 Martin Renvoize (ashimema) 2026-01-06 10:56:02 UTC
As always, many thanks for testing David :)
Comment 12 Martin Renvoize (ashimema) 2026-01-06 10:57:00 UTC
In fact, thank you both.. I somehow completely missed Jan has tested and signed off too!
Comment 13 Jonathan Druart 2026-01-06 12:23:24 UTC
Created attachment 190927 [details] [review]
Bug 41520: Add tests for extended_attributes in ERM agreements API

This patch adds api unit tests for the extended_attributes functionality in the
ERM agreements API to ensure that:

1. Extended attributes are correctly returned when embedded
2. The internal record_table field is not exposed via the API
3. Both single GET and list endpoints work correctly with extended_attributes

Test plan:
1. prove t/db_dependent/api/v1/erm_agreements.t
2. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 14 Jonathan Druart 2026-01-06 12:23:26 UTC
Created attachment 190928 [details] [review]
Bug 41520: Filter out record_table from AdditionalFieldValue API responses

Bug 35451 added a record_table field to the additional_field_values
database table for performance optimization (better joins). However,
this field was not added to the OpenAPI schema, and with
additionalProperties: false, the API validator rejects responses
containing it.

Rather than adding this internal implementation detail to the public
API schema, this patch adds a custom to_api method to
Koha::AdditionalFieldValue that filters out the record_table field.

This approach:
1. Keeps the database optimization from Bug 35451
2. Prevents internal implementation details from cluttering the API
3. Maintains context that API consumers already have from parent objects
4. Fixes OpenAPI validation errors for ERM agreements, licenses, and
   packages using extended_attributes

Test plan:
1. Create an ERM agreement with additional fields/extended attributes
2. Access the agreement via the API with extended_attributes embedded
3. Verify the response includes extended_attributes but not record_table
4. Confirm no OpenAPI validation warnings in plack-api-error.log
5. prove t/db_dependent/api/v1/erm_agreements.t
6. Verify all tests pass

Signed-off-by: Jan Kissig <bibliothek@th-wildau.de>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 15 Lucas Gass (lukeg) 2026-01-06 14:34:30 UTC
Nice work everyone!

Pushed to main for 26.05