-
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
Fix callback to only run before update #1001
Conversation
`before_save` doesn't accept `:on` as an argument, so this callback was actually running on all save events, not just on update. rails/rails#17622 Depending on what `reset_timestamp_attrs_for_update_if_needed` does, this might need to be backported to older versions. I've submitted a PR to Rails to raise an exception when unexpected arguments are passed... unsure if an exception is the right way to go when there might be quite a few gems with this bug. rails/rails#30919
Hi Sean, Thanks for finding this issue, and for patching it in rails. APIs that do not validate their input are just asking for trouble, aren't they?
Basically, it calls The MySQL tests are failing, e.g.
Given that only MySQL is failing, and other RDBMS' are passing, and it's timestamp related, I'm guessing this is due to MySQL's lack of fractional seconds precision. Or, maybe the test is just written poorly. |
Well the failing test doesn't actually fail on an update, it fails on reifying a deleted version. Hmm but only MySQL is failing... Perhaps it just needs to be changed to |
Yeah, but that |
I'd expect that Which is doubly confusing because the test passes for SQLite and Postgres. |
Yeah, it's just calling
😆 Yeah. Well those two RDBMS have fraction-seconds precision, so maybe their timestamps are changing by a fraction of a second when we call |
I wonder if the order of callbacks matters? The simplest/safest thing we can do is to stick with |
I switched it back to |
They did ¯\(ツ)/¯ |
Works for me, thanks Sean. |
Happy to help. Here's hoping the Rails PR gets merged; it's such an unfortunate bug. |
before_save
doesn't accept:on
as an argument, so this callback was actually running on all save events, not just on update.rails/rails#17622
Depending on what
reset_timestamp_attrs_for_update_if_needed
does, this might need to be backported to older versions.I've submitted a PR to Rails to raise an exception when unexpected arguments are passed... unsure if an exception is the right way to go when there might be quite a few gems with this bug.
rails/rails#30919