Bug 20750 adds the ability for events on ILL requests to be logged in the action logs. Currently changes to request status can be logged. However, when a request is deleted, the logs associated with that request are not. Since the request ID then becomes available, the next time a request is created, it will re-use the ID of the deleted request and instantly be associated with the log entries for that request. It's not currently possible to fix this since C4::Log doesn't provide any methods to delete log entries. So I'm going to add an enhancement bug for that.
Would one option be to not reuse the ID? Or have a real PK that is used instead of the ID used?
illrequests.illrequest_id is an auto_increment column, which is inline with the vast majority of primary key columns in Koha. Googling around suggests that MySQL/MariaDB shouldn't reuse deleted values in auto_increment columns, which was always my understanding also. However, I'm seeing log entries associated with requests where the log entries are dated before the request was created. My assumption was that IDs were being re-used, though, I have failed to replicate that behaviour. So perhaps the problem is not caused by that after all. I believe though that the bug is still valid. If a request is deleted, its log entries should be also. Due to the inability to create a foreign key on action_logs.object (due it potentially referring to many different keys), and therefore the inability to create a cascade, I believe we should do this cleanup manually.
I believe this might be a WONTFIX since we never clean up action_logs if something is deleted (the action_logs usually also contain the information, that something WAS deleted in the first place). Then you can use cleanup_database.pl to clean action_logs: https://git.koha-community.org/Koha-community/Koha/src/branch/master/misc/cronjobs/cleanup_database.pl --log-modules Specify which action log modules to trim. Repeatable. --preserve-log Specify which action logs to exclude. Repeatable. --logs DAYS purge entries from action_logs older than DAYS days. Defaults to 180 days if no days specified.