Bug 37622 - "location" header is set for non-POST routes
Summary: "location" header is set for non-POST routes
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: ERM (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: Hammat wele
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords: release-notes-needed
Depends on: 38929
Blocks:
  Show dependency treegraph
 
Reported: 2024-08-12 21:23 UTC by Hammat wele
Modified: 2025-09-26 16:40 UTC (History)
9 users (show)

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


Attachments
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles (3.65 KB, patch)
2024-08-12 21:41 UTC, Hammat wele
Details | Diff | Splinter Review
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles (2.57 KB, patch)
2025-01-15 13:32 UTC, William Lavoie
Details | Diff | Splinter Review
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles (3.80 KB, patch)
2025-04-09 16:40 UTC, William Lavoie
Details | Diff | Splinter Review
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles (3.88 KB, patch)
2025-09-15 08:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 37622: Adjust 'location' header test (3.68 KB, patch)
2025-09-15 08:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 37622: Fix add_debit (1.01 KB, patch)
2025-09-15 08:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 37622: Remove location from 2 preservation 'update' routes (1.59 KB, patch)
2025-09-15 08:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles (3.94 KB, patch)
2025-09-24 13:33 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 37622: Adjust 'location' header test (3.75 KB, patch)
2025-09-24 13:33 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 37622: Fix add_debit (1.08 KB, patch)
2025-09-24 13:33 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 37622: Remove location from 2 preservation 'update' routes (1.65 KB, patch)
2025-09-24 13:33 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Hammat wele 2024-08-12 21:23:13 UTC
Error in erm module when editing an agreement, a license, a package or a title

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title
Comment 1 Hammat wele 2024-08-12 21:41:11 UTC
Created attachment 170248 [details] [review]
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title
Comment 2 Pedro Amorim 2024-08-13 08:32:04 UTC
I can't reproduce the error. Creating and editing an agreement works for me as expected, no errors. Running on latest main. Can you please revisit the test plan or verify how exactly to reproduce the error? Thanks.
Comment 3 Hammat wele 2024-08-13 14:46:16 UTC
(In reply to Pedro Amorim from comment #2)
> I can't reproduce the error. Creating and editing an agreement works for me
> as expected, no errors. Running on latest main. Can you please revisit the
> test plan or verify how exactly to reproduce the error? Thanks.

When I follow the previous steps, i can't edit a agreement and i got 

Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data    as error

And when i inspect the page before submitting the form i can see in the console the following error

PUT http://master-intranet/api/v1/erm/agreements/api/v1/erm/agreements/2/2    HTTP/1.1 404 Not Found
Comment 4 Pedro Amorim 2024-08-14 11:08:16 UTC
Still can't reproduce on current main branch.
Are you able to provide more information? What version is this happening on? Are you encountering this issue on a dev k-t-d environment or on a live environment?
Comment 5 William Lavoie 2025-01-14 19:17:49 UTC
I was able to reproduce the error on the main on a live environment by following the test plan. The patch worked also.
Comment 6 William Lavoie 2025-01-15 13:32:25 UTC
Created attachment 176567 [details] [review]
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title
Comment 7 William Lavoie 2025-01-15 13:32:41 UTC
Rebased
Comment 8 Jonathan Druart 2025-01-15 14:17:01 UTC
This patch removes the support of additional fields for agreements on edition.
Comment 9 Jonathan Druart 2025-01-15 14:18:40 UTC
And I don't get the error on main.

Please test on a sandbox/main and confirm you get the error there.
Comment 10 William Lavoie 2025-04-09 16:40:31 UTC
Created attachment 180743 [details] [review]
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title
Comment 11 William Lavoie 2025-04-09 16:49:43 UTC
Apologies for the delayed answer. 

You are correct this seems to be a local problem as I am unable to reproduce it on a ktd or a sandbox.

However, why is location set in the response headers if the status code returned is 200? According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Location it should be used only for 3xx and 201 codes.
In my case, having location in the headers triggers a redirection and returns a 302 code, instead of the expected 200. 

I rebased and put back the support of additional fields for agreements.
Comment 12 Hammat wele 2025-09-12 13:43:29 UTC
(In reply to Pedro Amorim from comment #4)
> Still can't reproduce on current main branch.
> Are you able to provide more information? What version is this happening on?
> Are you encountering this issue on a dev k-t-d environment or on a live
> environment?

(In reply to Jonathan Druart from comment #9)
> And I don't get the error on main.
> 
> Please test on a sandbox/main and confirm you get the error there.

I am now able to reproduce the issue on a dev k-t-d environment. 
To reproduce it we need first Plack to be stopped

Steps to reproduce on a k-t-d environment
1. Enter the Koha container:
    docker exec -it kohadev-koha-1 bash
2. Stop Plack:
    koha-plack --stop kohadev
    koha-plack --disable kohadev
4. Restart Apache:
    service apache2 restart

Then follow the test plan of this bug (Note: the interface will be slower without Plack.)
Comment 13 Jonathan Druart 2025-09-15 08:42:31 UTC
Created attachment 186395 [details] [review]
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 14 Jonathan Druart 2025-09-15 08:42:36 UTC
Created attachment 186396 [details] [review]
Bug 37622: Adjust 'location' header test

We were ignoring whole files and parsing the whole file to check if
location and 201 were together. It's way better to check per subroutine.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 15 Jonathan Druart 2025-09-15 08:42:42 UTC
Created attachment 186397 [details] [review]
Bug 37622: Fix add_debit

We should not call discard_changes after accessing ->id but before

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 16 Jonathan Druart 2025-09-15 08:42:50 UTC
Created attachment 186398 [details] [review]
Bug 37622: Remove location from 2 preservation 'update' routes

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 17 Jonathan Druart 2025-09-15 08:43:41 UTC
The "location" header should only be in the response of POST routes.
Comment 18 Martin Renvoize (ashimema) 2025-09-24 13:33:27 UTC
Created attachment 186879 [details] [review]
Bug 37622: Error in erm module when editing an agreement, a license, a package or a titles

To reproduce

1- Enable the ERMModule system preference
    1- Go to Administration > System Preferences
    2- Search for ERMModule
    3- Change the value to "Enable"
    4- Click on "Save all e-resource management preferences"
    5- Return to the main screen
1- Create an agreement
    1- Go to e-resource management
    2- Click on "Agreements"
    3- Click on "New agreement"
    4- Fill out the form (mandatory fields)
        - Agreement name: Natural Medicines
        - Status: Active
    5- Click on "Submit"
2- Edit the agreement
    1- Click on "Agreements"
    2- Click on "Edit" to the right of the Natural Medicines agreement
    3- Click on "Submit"
        --> Something went wrong: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
We got the same error when editing a license, a package or a title

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 19 Martin Renvoize (ashimema) 2025-09-24 13:33:30 UTC
Created attachment 186880 [details] [review]
Bug 37622: Adjust 'location' header test

We were ignoring whole files and parsing the whole file to check if
location and 201 were together. It's way better to check per subroutine.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 20 Martin Renvoize (ashimema) 2025-09-24 13:33:32 UTC
Created attachment 186881 [details] [review]
Bug 37622: Fix add_debit

We should not call discard_changes after accessing ->id but before

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 21 Martin Renvoize (ashimema) 2025-09-24 13:33:34 UTC
Created attachment 186882 [details] [review]
Bug 37622: Remove location from 2 preservation 'update' routes

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 22 Lucas Gass (lukeg) 2025-09-26 16:39:13 UTC
Nice work everyone!

Pushed to main for 25.11