Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
AR: take precision into count when assigning a value to timestamp attribute #20317
Consider this following on MySQL (that have 0 precision on datetime by default):
d1 = Developer.create!(name: 'bogdan') d2 = Developer.find(d1.id) d1.created_at.usec # => 837728 d2.created_at.usec # => 0 # It results in a madness: d1.created_at == d2.created_at # => false d1.cache_key == d2.cache_key # => false
Rails 4.1.10 and master are affected. Not sure about others.
Timestamp column can have less precision than ruby timestamp
If the precision is low enough, (mysql default is 0 so it is always low
In order to fix that we just use a precision of a column when assigning a value to the timestamp attribute as time object (not as string - that seems working).
When I've applied a patch, the new problem raised: existing tests are written incorrectly for mysql that have 0 precision by default.
In order to make them pass I've set the precision for tables that are used to check if
It should be consistent. It can be done by setting up a
@rafaelfranca yes it will: at the rails level, unsupported precision works like
The fact that older mysql don't support precision raises the following problem:
def test_cache_key_changes_when_child_touched owner = owners(:blackbeard) pet = pets(:parrot) owner.update_column :updated_at, Time.current key = owner.cache_key assert pet.touch assert_not_equal key, owner.reload.cache_key end
It will only work stable if there will be at least 1 second between the creation of
I'll think more how we can solve it. If you have an idea, please share with me.
Hope I've fixed the build on mysql5.6: I made it differently with
Can someone advice how to go from PR to corresponding CI build? Find it here: https://travis-ci.org/rails/rails/pull_requests manually seems impossible.