-
Notifications
You must be signed in to change notification settings - Fork 25
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
always set memo_wise hash if not set for some reason #321
base: main
Are you sure you want to change the base?
Conversation
Interesting, thanks @joevandyk ! Would you be able to write a failing test that passes with this change? If you need help navigating our test files let me know and I can try to add one based on your previous example. |
3310e4a
to
fae1c66
Compare
@JacobEvelyn The tests probably aren't formatted exactly as they should be, but I think it illustrates the problem. |
@JacobEvelyn any thoughts on this one? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #321 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 2 2
Lines 179 180 +1
Branches 88 88
=========================================
+ Hits 179 180 +1 ☔ View full report in Codecov by Sentry. |
Hey @joevandyk ! Thanks so much for the failing tests, and so sorry to have taken so long to get back to you. I agree this is a problem that should be fixed. I don't love how the
Is there a way to detect this case better and initialize the instance variable then? |
Thanks for looking at this! To be honest, I don't know why the instance variable isn't always initialized. This fix is a bandaid for what I assume is properly initializing the variable, unfortunately my Ruby's not good enough to understand this gem at that deep a level. :) |
Okay I dug in a bit more here. The challenge is that even if we change our def klass.included(base)
base.class_eval <<~HEREDOC, __FILE__, __LINE__ + 1
def initialize(#{ALL_ARGS})
MemoWise::InternalAPI.create_memo_wise_state!(self)
super
end
HEREDOC
end this only works if the class we care about defines class MyClass
def initialize(*) ; end
include MyModule
end This is because the It's not ideal, but I wonder if a solution for your use case is to just use There's also some other work going on right now in #324 and #326 to fix some similar issues, and I'm trying to see if a similar solution would work here. |
What if we change MemoWise to actually error out if we use include instead of prepend? |
@ms-ati I think the issue is it's not caused by someone @joevandyk I'm no longer confident I can get something working on the code to resolve this issue for you. Would one of these workarounds work for you instead?
|
QQ: What would happen if everything stayed the same (that is: Does that still trigger the MemoWise initialize? |
@JacobEvelyn I am wondering if we should consider making use of Module#method_added as a callback, and if the method added is |
I’ve had issues with memo_wise and ActiveRecord’s latest marshalling format. ActiveRecord.marshalling_format_version = 7.1
class User < ActiveRecord::Base
prepend MemoWise
end
Rails.cache.fetch("test") { User.new }.instance_variable_get(:@_memo_wise)
# => {}
Rails.cache.fetch("test") { User.new }.instance_variable_get(:@_memo_wise)
# => nil This branch fixes the issue 🙏🏻 |
Fixes #302 for us
Before merging:
README.md
and update this PRCHANGELOG.md
, add an entry following Keep a Changelog guidelines with semantic versioning