-
Notifications
You must be signed in to change notification settings - Fork 37
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
Fixes bug? datetime and time types should still use nil adapter #242
base: master
Are you sure you want to change the base?
Conversation
Thanks! I actually am not following this and don't understand the difference, I think you've gone somewhere I haven't explored in the attribute adapters. Is it feasible to provide a test that fails without this change? That would be best, to prevent any regression too. Alternately, if that's not feasible, if you could just describe more the situation where this makes a difference, I would find that helpful! I'm not following what "fall back to needing a database" means (in what circumstances?). Thank you for your contribution! |
The change is ensuring lookup_kwargs always still includes { adapter: nil }, so that #41 doesn't happen. This is setting up the options hash called lookup_kwargs that will be passed to the ActiveRecord::Type.lookup Because ActiveRecord::Type.lookup may/will try to connect to a database in some situations. So... { adapter: nil } needs to be passed as one of the options to the lookup. And we can see in the code that the option is indeed set.... but that it gets fully overwritten if the attribute type is :datetime or :time. |
Aha, thanks! I had forgotten about that bug, and plus I see we thought we had fixed it! Maybe it came back, or just for datetime, because we lacked a test for it! I am not sure if there is a good way to make a test, can you think of any? Either way, thank you! |
Oh aha, maybe just need to add OK, i'll get on it, thanks! |
Yes... just for :datetime and :time Ill think about how to write a test.... |
yah... that should trigger it. |
I added to the testcase. |
Interesting, thanks! Definitely kind of mysterious. Have you encountered the actual real failure in the real world, where you are getting an exception when the DB isn't yet available? If so, can you share the stack trace from that actual error? |
Still failing your new test in Rails 6.0, which is weird. And I don't know we really need to keep supporting Rails 6, but I try not to drop rails versions without a major version release. I can work on trying to figure out the right way to add these tests when I have time, but might take me a bit. Is this problem urgent for you? |
No. This is not urgent. I can work around it. I was just trying to be helpful and squash a bug. Ill put up a stack trace for it later as well. I appreciate your time. |
Oh no worries, you have indeed been super helpful! Thank you for reporting this with the fix! I was just asking if it was urgent because I felt bad and would have tried to get this merged sooner if it were! I've got a few balls in the air at the moment, but you are welcome to do as much work on it as you want, but no pressure I also don't expect you to, and I promise I will circle back to it later when I have a moment! I just ideally want to understand a bit more about what's going on before I merge it, but I appreciate your helpfulness, thank you! |
So I have figured out this is specific to rails 6.0 & 6.1 Im thinking changing the test to something like
may work better.... |
Interesting! But...
Does this imply that the problem we are trying to solve doesn't exist in 7.0 and above? (7.0 and below are all EOL from Rails). Still nothing wrong with cleaning this up and putting in a test for regression, but curious.... you ran into this problem yourself @jNicker? Was it on a Rails prior to 7.0? |
Yes. I am currently upgrading a clients application from Rails 5.X to latest... So yes... I think it only exists in EOL Rails at this point. |
Oh nice! Still no reason not to fix it though! I'll try to get it merged early next week! Thank you! |
Oh yeah, that's a great way to do it! Actually check for connected, nice! I'll put that in tomorrow prob, and give you credit, or feel free if you want to. |
Updated. |
I believe that you still want to keep the adapter as nil, otherwise you fall back to needing a database.