-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Still touch associations when theres no timestamp #14390
Conversation
Prior to Rails 4.0.4 when touching a object which doesn't have timestamp attributes (updated_at / updated_on) rails would still touch all associations. After 73ba2c1 it updates associations but rollsback because `touch` would return nil since there's no timestamp attribute
@@ -340,6 +340,17 @@ def test_belongs_to_with_touch_option_on_touch | |||
assert_queries(1) { line_item.touch } | |||
end | |||
|
|||
def test_belongs_to_with_touch_option_on_touch_without_updated_at_attributes | |||
assert !LineItem.column_names.include?("updated_at") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use assert_not
?
I'm more to revert that commit than changing this. @carlosantoniodasilva are you sure # Saves the record with the updated_at/on attributes set to the current time.
# Please note that no validation is performed and only the +after_touch+
# callback is executed. |
cc @airhorns |
my two cents on this: If this were catch before releasing 4.0.4 I would revert it, as indeed it should not be in a minor version. However as this is part of 4.0.4 already, and we can fix it without impacting too much, I would go with the fix for version 4.0.5. |
This fix is wrong in my opinion and could cause more regression. But of course we could provide another fix we can keep this change. |
No need to ask "what if"—we can revert now, then revert the revert when a fix is ready. |
I'm certainly not the best person to tell it but fixing this some other way could add a lot of complexity which might not be worth it. So maybe we could just live with it. I only opened this because I noticed this failing spec on spree build and thought I should report but I don't think the other change should be reverted. It didn't actually cause us any real trouble so far. Possibly easy fix for everyone would be to add the missing timestamps fields to get rid of the rollbacks. |
Hey guys this other approach just came to mind: def touch(*) #:nodoc:
if timestamp_attributes_for_update_in_model.empty?
super
else
with_transaction_returning_status { super }
end
end Wdyt? build is still happy. |
Original author of the commit which introduced this bug here - sorry! Just wanted to throw in my two cents however. If we make So, I'd rather leave it to the user to properly call touch on models instead of changing the above subtle behaviour, but in all fairness this kind of violates the Tell Don't Ask principle... Would it be so bad for touch to return true if there were no timestamp columns? |
I was thinking about this. I guess it may be fine since the touch operation will still occurs in the associated models if the model don't have timestamp columns. Also reverting your patch also brings a undesirable behavior that I'll check the patch again later. |
I am 👍 on this patch.. @rafaelfranca any final remarks about it? anything else we need to get done before 🚢 this? |
I'll merge this today. |
nice thanks @rafaelfranca I'll make the changes you requested above later today |
Hey guys, sorry I somehow missed the thread here. I do think after_commit/rollback callbacks should be triggered on touch, so I guess fixing the bug in question here is the way to go (with this or a different approach). Thanks for handling this ❤️ |
Still touch associations when theres no timestamp
Still touch associations when theres no timestamp
Still touch associations when theres no timestamp
Still touch associations when theres no timestamp
Done |
thanks all ❤️ |
Prior to Rails 4.0.4 when touching a object which doesn't have timestamp
attributes (updated_at / updated_on) rails would still touch all
associations. After 73ba2c1 it updates
associations but rollsback because
touch
would return nil sincethere's no timestamp attribute.
This sounds a bit insane (touching an object without timestamps) but I came through it today while upgrading and just felt like reporting anyway due to being a change of behaviour between minor releases.
The following would pass on 4.0.3 but fails on 4.0.4