Skip to content

Database objects do not register < 1sec changes #8460

Closed
wesdotcool opened this Issue Dec 8, 2012 · 5 comments

4 participants

@wesdotcool

I just upgraded from rails 3.1.3 to rails 3.2.9

It seems database objects that keep track of postgres DateTime objects do not register changes under 1 second

1.9.3-p327 :001 > e = Employee.last
1.9.3-p327 :002 > e.created_at
 => Wed, 14 Nov 2012 11:43:18 PST -08:00
1.9.3-p327 :003 > e.created_at.to_f
 => 1352922198.0550148
1.9.3-p327 :004 > e.created_at += 0.5
 => Wed, 14 Nov 2012 11:43:18 PST -08:00
1.9.3-p327 :006 > e.changed?
 => false
1.9.3-p327 :007 > e.created_at.to_f
 => 1352922198.0550148
1.9.3-p327 :008 > e.created_at += 0.95
 => Wed, 14 Nov 2012 11:43:19 PST -08:00
1.9.3-p327 :009 > e.changed?
 => true
1.9.3-p327 :010 > e.created_at.to_f
 => 1352922199.0050151
1.9.3-p327 :011 > e.created_at.class
 => ActiveSupport::TimeWithZone

However less than 1 second changes to time objects in rails 3.1.3 worked as expected.

@carlosantoniodasilva
Ruby on Rails member

/cc @pixeltrix any thought about this one?

@pixeltrix
Ruby on Rails member

The problem was introduced in 3.2.9 with the 8905c1f commit, which basically strips off the usec value from the time value so unless additional fraction takes it across the second boundary the changed value won't be written. This was ostensibly a fix for MySQL related bug (#6975) since it's only recently started to support fractional seconds in DATETIME columns.

The 8905c1f commit needs to be reverted as it's the wrong fix. We also need to revert e9d2ad3 which is the equivalent commit in master. I'll reopen #6975 and fix that and add a regression test to ensure that fractional timestamp changes are tracked.

@carlosantoniodasilva
Ruby on Rails member

Thanks for the detailed explanation @pixeltrix :)

@pixeltrix pixeltrix was assigned Dec 9, 2012
@carlosantoniodasilva
Ruby on Rails member

/cc @rafaelfranca ping me or @pixeltrix later if you have any doubt.

@rafaelfranca
Ruby on Rails member

👍

@pixeltrix pixeltrix added a commit that referenced this issue Jan 22, 2013
@pixeltrix pixeltrix Add failing test case for #8460
Add a test case to ensure that fractional second updates are detected.
7ee7671
@pixeltrix pixeltrix added a commit that referenced this issue Jan 22, 2013
@pixeltrix pixeltrix Revert "Merge pull request #6986 from kennyj/fix_6975"
This reverts commit 8905c1f.

Closes #8460

Conflicts:
	activerecord/test/cases/dirty_test.rb
97a4db9
@pixeltrix pixeltrix added a commit that referenced this issue Jan 22, 2013
@pixeltrix pixeltrix Add failing test case for #8460
Add a test case to ensure that fractional second updates are detected.
1cf73a6
@pixeltrix pixeltrix added a commit that closed this issue Jan 22, 2013
@pixeltrix pixeltrix Revert "Round usec when writing timestamp attribute."
This reverts commit e9d2ad3.

Closes #8460

Conflicts:
	activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
	activerecord/test/cases/dirty_test.rb
5c4a186
@pixeltrix pixeltrix closed this in 5c4a186 Jan 22, 2013
@tenderlove tenderlove added a commit that referenced this issue Jan 22, 2013
@tenderlove tenderlove Merge branch 'master' into jobs
* master:
  Less strict activerecord-deprecated_finders version
  Revert "Round usec when writing timestamp attribute."
  Add failing test case for #8460
  Lets kepp using Ruby 1.9 syntax
  Only check for unpermmited parameters if action_on_unpermitted_parameters is present
  Revert "Merge pull request #7873 from steveklabnik/update_initializer"
  Revert "Set the default timezone after the initialization since the configuration"
  Revert "updating i18n guide with locale config location."
  avoid creating an object in every call
  Remove unnecessary require
  Re-do Getting Started application with Rails 4.
  fixing link to validations guide in getting started guide
  Getting Started Guide: strong_parameters
  Fix images in getting started guide.
  Remove tabs, use spaces ✂️
  Whitespaces ✂️
f0f146d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.