-
Notifications
You must be signed in to change notification settings - Fork 901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PaperTrail always enabled in controllers. #635
Comments
Can you reproduce this issue with the latest version of PaperTrail (currently 4.0.0)? What does your endpoint look like?
Can you submit a PR with a failing test that demonstrates the issue? |
Sorry, I am not able to submit a PR with failing test with this depository, due to my unfamiliarity with the codebase and lack of time. And I have since used a custom solution to track changes for some areas of the app. But here is my sample app: https://github.com/randomor/paperapp/blob/master/app/controllers/posts_controller.rb#L12 |
I tried out your sample app (version fa77aae3c). It works for me. Here are the steps I took:
Produces the following output:
I wonder what we are doing differently? Any ideas? |
Yes. Test will pass. But if you do rails s and try hit the route you will see it log false. |
You mean
Let me dig around and see if there's any explanation for that. It definitely seems wrong. |
Sorry. Yes. That's what I meant. Thanks! On Fri, Oct 16, 2015 at 9:20 PM, Jared Beck notifications@github.com
|
Perhaps I can shed some light on this. PR #541 introduces a 'thread safe' Furthermore, this means that disabling module PaperTrail
private
def self.paper_trail_store
@paper_trail_store ||= { :request_enabled_for_controller => true }
end
end It looks like this could do with a bit more attention. |
Thanks Howard, that's helpful. Given that So, I guess we should look for a way to at least disable PT in test env. Any ideas? |
@jaredbeck I don't see very much discussion on the pros and cons of making it thread-local. Perhaps @batter at the time hadn't considered this sort of scenario? If we can switch back to it being a global variable, a thread-safe implementation is simple to create: def initialize
@mutex = Mutex.new
end
def enabled
@mutex.synchronize do
@enabled
end
end
def enabled=(enabled)
@mutex.synchronize do
@enabled = enabled
end
end |
Neither do I, but I haven't looked super-hard. If we were to change it back to "global" (technically, a singleton ivar) we'd still have |
@watsonbox - Thanks for chiming in here, I see what you're saying. When you overrode it to disable it in your test suite did you actually set I've been thinking about this and I'm wondering whether we could have some sort of way to have an optional initializer for the gem which loads up an key value store of the initial state of the |
Hi Ben, looks like we're both thinking about this tonight. You may want to review #717 first, or use it as a starting point, or whatever. I'm looking forward to seeing what you come up with too, or any suggestions you have. |
@jaredbeck - Thanks, that looks neat, I will have to read that more closely tomorrow when I'm not so sleepy, but that looks like a promising start. I wish I was more knowledgable about working with threading to be honest. |
@batter can you comment on this? #635 (comment) |
Moving it back to a "global" variable with a thread-safe implementation should make #717 unnecessary |
A single unsafe variable would certainly be simpler than #717, and I'm a big fan of simpler. Regarding the term "thread-safe", I would expect a "thread-safe" implementation to avoid the following error:
From thread A's perspective is this actually "thread-safe"? I am not convinced it is. The implementation suggested above (#635 (comment)) is susceptible to this error. |
Why would different threads want it set differently in the first place? That's what I don't understand, that wasn't explained in #541. |
And to clarify on what "thread-safe" means, it means that there would never be a race condition if two threads tried reading or writing to the variable at the same moment. The mutex puts a lock on the variable, so if two threads try accessing it at the same time, they happen serially instead of simultaneously. https://en.wikipedia.org/wiki/Thread_safety Something can be thread-safe without providing thread-local variables. |
I don't have a good answer for this, actually. I was thinking about threaded servers like puma, and that people might want to disable PT for an entire thread, but in reality |
Closed by #723, a breaking change, scheduled for 5.0 release. |
I'm using Puma as my web server, and have in
application.rb
:I'm able to login to
rails c
and see:PaperTrail.enabled? #=> false
However, when I'm posting a request to one of my endpoint with
binding.pry
, and when I doPaperTrail.enabled? #=> true
I've created an app from scratch and it's running webrick and still has the same issue. Is this a bug or am I missing something?The text was updated successfully, but these errors were encountered: