This project is archived and is in readonly mode.
Dirty checking blocks MySQL updates with trailing spaces
Reported by Student | December 22nd, 2008 @ 09:15 PM | in 3.x
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.
Comments and changes to this ticket
-
Frederick Cheung December 22nd, 2008 @ 11:10 PM
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?
-
Pratik February 24th, 2009 @ 04:13 PM
- State changed from new to incomplete
Will reopen when there's a patch.
Thanks.
-
Santiago Pastorino February 2nd, 2011 @ 05:03 PM
- 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.
-
Santiago Pastorino February 2nd, 2011 @ 05:03 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>