#624 ✓resolved
dcgrigsby

dm-is-versioned - updating a param more than once between saves results in wrong value being saved

Reported by dcgrigsby | October 30th, 2008 @ 10:04 AM

Using dm-is-version, do the following:


@story = Story.create(:title => "A Story")
@story.title = "An Inner Update"
@story.title = "An Updated Story"
@story.save

The versioned copy should have "A Story" as its title value, but instead has "An Inner Update."

Easy (two character) fix -- in the before attribute_set hook, change "=" to "||=" like so:


self.before :attribute_set do |property, value|
  pending_version_attributes[property] ||= self.attribute_get(property)
end

An example where this shows up in the wild:

merb_dm_xss_terminate is a before_save filter that iterates through each property and filters out cross site scripting values. so, e.g., 1. you grab an existing Story from the database and 2. update the title. the original (from the db) title is saved in pending_version_attributes. you then call the save method, which triggers merb_dm_xss_terminate that updates all of the attributes. the new title (which was set in 2) gets written to the versioned table.

Patch file with (1) rspec to demonstrate and (2) a fix attached.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages