Bug 36542 - In C4/AddBiblio, plugin hook after_biblio_action is triggered before the record is actually saved
Summary: In C4/AddBiblio, plugin hook after_biblio_action is triggered before the reco...
Status: Patch doesn't apply
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Arthur Suzuki
QA Contact: Tomás Cohen Arazi (tcohen)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-08 09:11 UTC by Arthur Suzuki
Modified: 2024-07-04 21:27 UTC (History)
3 users (show)

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


Attachments
Plugin which demonstrate the issue (29.86 KB, application/zip)
2024-04-10 09:09 UTC, Arthur Suzuki
Details
Bug 36542: after_biblio_action plugin hook is now called after the dbx transaction is finished (1.25 KB, patch)
2024-04-10 11:40 UTC, Arthur Suzuki
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur Suzuki 2024-04-08 09:11:53 UTC
To reproduce :
1) Install a plugin which uses the biblionumber of a created record in the "after_biblio_action".
2) Verify the biblionumber is missing

This is because the call to the hooks is done before the DB transaction is actually done (in AddBiblio function).
Comment 1 Arthur Suzuki 2024-04-10 09:09:17 UTC
Created attachment 164589 [details]
Plugin which demonstrate the issue

I made a plugin which demonstrate the issue.
After installing the plugin in KTD, you'll have to open /var/log/koha/plack-intranet-error.log.

Then, if you create a record, you'll see that when the "after_biblio_action" hook is called, the biblio object is available for some Koha::Biblios namespace thanks to some caching mechanism (first warn in the plugin code is not triggered).
However, when the hook is called, it is actually not yet saved to DB.
This can be verified by doing a call to an API during the call, and see that this api call do not find the record.
This test is implemented in the plugin and you will see in the plack-intranet-error.log that the record is not found.
Comment 2 Arthur Suzuki 2024-04-10 11:40:09 UTC
Created attachment 164607 [details] [review]
Bug 36542: after_biblio_action plugin hook is now called after the dbx transaction is finished
Comment 3 Arthur Suzuki 2024-04-10 11:41:15 UTC
if the patch is applied, the log will contains the record data.
Comment 4 Jonathan Druart 2024-04-17 09:10:33 UTC
We need to log the modified version of the record. We must log after the hook call IMO.
Comment 5 Chris Cormack 2024-07-04 21:27:12 UTC
We have a merge commit as the code has moved on a little bit. Can you have a quick look please Arthur.