Destroying dynamic storage containing attachments throws "storage not registered" error during after_commit
This is a bit complex, but I'll try to explain it as clearly as I can.
I'm using dynamic_storage to set up a set of storage locations in my system, which the user can add, remove, etc at runtime. The class that represents this is a Library in my system; each one has (is) a different Shrine storage.
There are items in the libraries that have attachments, and they automatically use the storage for the library that they're assigned to.
The problem comes with deletion. If we have a library with some items in, and we destroy it, the items also get destroyed using the normal rails dependent method.
However, after that is all committed and the items and library have been destroyed, the items in the library then call their after_commit hook: https://github.com/shrinerb/shrine/blob/1ce6da4be0ca62ecd5776f107fcd0d657b773f28/lib/shrine/plugins/activerecord.rb#L48
This hook tries to look up the storage location for the item (presumably in the attached? method, I've not delved inside that yet), which fails with a Shrine::Error saying the storage isn't registered. That's correct and expected, because the storage has been deleted; however, that after_commit hook doesn't handle the situation, so the error propagates up. I'm currently handling it by just discarding the error, but that feels a bit messy (https://github.com/manyfold3d/manyfold/pull/3793)
I'm not sure what the right solution is here. Perhaps the after_commit hook should simply fail quietly if the storage isn't available any more? Or, maybe my blanket absorbing of errors on deletion is the best solution available. 😁
Any thoughts are most welcome... if there is a better way, I'm happy to do the work to improve it, but I'm not quite sure at the moment how to attack it.