Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Setting a nil datetime attribute to blank string incorrectly marks attribute as changed #8310

Closed
alisdair opened this Issue · 0 comments

2 participants

@alisdair

If a nullable datetime attribute is currently nil, setting its value to a blank string will retain the nil value, but incorrectly flag it as changed. In practice this will happen if the attributes are round-tripped via a view.

I am trying to track changes for this model:

class CreateArticles < ActiveRecord::Migration
  def change
    create_table :articles do |t|
      t.string :title
      t.datetime :started

      t.timestamps
    end
  end
end

This behaviour is incorrect:

>> a = Article.create(:title => "Testing")
>> a.started
=> nil
>> a.started = ''
=> ""
>> a.started
=> nil
>> a.changes
=> {"started"=>[nil, nil]}

@alisdair alisdair referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@alisdair alisdair referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@carlosantoniodasilva carlosantoniodasilva closed this issue from a commit
@alisdair alisdair Don't call will_change! for datetime nil->"".
Setting a nil datetime attribute to a blank string should not cause the
attribute to be dirty.

Fix #8310
fc4e387
@alan alan referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
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.