Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Dirty checking blocks MySQL updates with trailing spaces

#1616

MySQL text fields ignore trailing spaces when checking equality. As a result, an update which changes the trailing spaces will "fail" the dirty test and not actually be saved (although save will report success). It is necessary to do record.send(update_without_dirty) to bypass this behavior. (Is this SQL standard? If so, it affects all engines.)

I consider this to be a major gotcha--it was hard to catch, and required source diving to get around. Moreover, going so far inside the alias chain meant that quite a few things that I might have wanted to be handled for me were not.

Proposal: 1) If this behavior ("string " cannot be overwritten with "string" without calling a private method) is desirable, it really needs to be documented. 2) Dirty checking needs to be moved way up in the alias chain. Probably to just before validate. That way, if it needs to be bypassed, other callbacks are still used.

We're running 2.1.2 here, so I cannot easily determine if this still affects 2.2.

Reported by Student · December 22nd, 2008 @ 09:15 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung

    Well you can turn off partial updates on a per class which sounds like it would help:

    
    class Problematic < AR::Base
      self.partial_updates = false
    end
    

    I'm not sure I understand though. While mysql may ignore trailing spaces certain column types, ruby doesn't - the only thing I can see this doing is Active Record needlessly updating a column which won't actually be storing anything different. Can you provide a more detailed example of what goes wrong where?

    December 22nd, 2008 @ 11:10 PM

  2. Pratik
    Pratik
    • State changed from new to incomplete

    Will reopen when there's a patch.

    Thanks.

    February 24th, 2009 @ 04:13 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Tag changed from 2.1.2, dirty, mysql, update to 212, dirty, mysql, update
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:03 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:03 PM