
[PATCH] Collection#destroy! with LIMIT/OFFSET destroys all data
Reported by Lin Jen-Shin | January 6th, 2009 @ 11:09 AM
I am not familiar with database and SQL, so I didn't know there's no LIMIT/OFFSET in DELETE. It surprises me that the same Query would resolve different results in SELECT and DELETE. Please read example in Gist because I don't know how to format codes in Lighthouse:
I know raise ArgumentError in DataObjectsAdapter seems dirty, stupid, and inconsistent, since perhaps there's some data storages support delete data with offset and/or limit. But it really shocked me that I have accidentally deleted ALL records with something like: data.size # => 10; data.destroy! # => all gone...
It would be helpful for someone like me who wasn't familiar with SQL if any error would raise in this situation instead of silently delete all records. Many thanks for your listening.
cheers, Jen-Shin
Comments and changes to this ticket
-
Lin Jen-Shin January 6th, 2009 @ 11:11 AM
the above attachment was against sam/dm-core, here's dkubb/dm-core
-
Lin Jen-Shin January 6th, 2009 @ 11:12 AM
and the spec. I don't know why .should raise_error wouldn't work, so I just use regular rescue and check the exception here.
-
Dan Kubb (dkubb) January 8th, 2009 @ 04:25 AM
- Tag changed from collection, destroy!, patch to bug, collection, destroy!, patch
- State changed from unconfirmed to accepted
- Assigned user set to Dan Kubb (dkubb)
I was actually going to resolve this issue by using a subselect when a limit/offset is specified in the Collection that is being deleted. This should work fine on the 3 RDBMS, and if it doesn't in the future, I will raise some sort of exception from those.. or find an alternate work-around, like retrieving the rows directly, and then deleting them with an "IN" clause.
I am going to leave this ticket open, since what you are really reporting is that using Collection#delete with a limit/offset destroys all the data, not just the data in the Collection.
-
Dan Kubb (dkubb) January 8th, 2009 @ 04:25 AM
- Title changed from [PATCH] raise ArgumentError if LIMIT/OFFSET was set in query in Collection#destroy! to [PATCH] Collection#destroy! with LIMIT/OFFSET destroys all data
-
Dan Kubb (dkubb) May 28th, 2009 @ 03:43 AM
I can confirm this is resolved with dm-core/next. Attached is a script demonstrating the fix.
-
Dan Kubb (dkubb) May 28th, 2009 @ 04:52 AM
- State changed from accepted to resolved
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »