You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Executes the given method or block without creating a new version.defwithout_versioning(method=nil)paper_trail_was_enabled=self.paper_trail_enabled_for_modelself.class.paper_trail_offmethod ? method.to_proc.call(self) : yieldensureself.class.paper_trail_onifpaper_trail_was_enabledend
If multiple threads call this method at the same time, Bad Things will happen.
For example, versioning could be turned off for all threads, causing no threads to save any versions during the duration of this method call.
Or, one thread could have set self.paper_trail_enabled_for_model to false temporarily. Then, when without_versioning is called, paper_trail_was_enabled will be false. So versioning will be turned off permanently from that point forward.
The solution is probably to use a thread local variable for self.paper_trail_enabled_for_model. This will also cause self.class.paper_trail_off and self.class.paper_trail_on to be thread local.
The text was updated successfully, but these errors were encountered:
To put this into context, I'm running my Rails app in JRuby under Torquebox, so thread safety is a real issue for me.
I'm working on a pull request for this that will use PaperTrail's paper_trail_store to track if Paper Trail is enabled on a particular model.
I believe this will also fix #307 by doing away with setting and unsetting the paper_trail_enabled_for_model class attribute (which apparently isn't thread safe).
If multiple threads call this method at the same time, Bad Things will happen.
For example, versioning could be turned off for all threads, causing no threads to save any versions during the duration of this method call.
Or, one thread could have set
self.paper_trail_enabled_for_model
to false temporarily. Then, whenwithout_versioning
is called,paper_trail_was_enabled
will be false. So versioning will be turned off permanently from that point forward.The solution is probably to use a thread local variable for
self.paper_trail_enabled_for_model
. This will also causeself.class.paper_trail_off
andself.class.paper_trail_on
to be thread local.The text was updated successfully, but these errors were encountered: