Ticket #7298: prevent_update_queryset_r7599.patch
File prevent_update_queryset_r7599.patch, 1.5 KB (added by , 16 years ago) |
---|
-
django/db/models/query.py
292 292 Updates all elements in the current QuerySet, setting all the given 293 293 fields to the appropriate values. 294 294 """ 295 assert self.query.can_filter(), \ 296 "Cannot update a query once a slice has been taken." 295 297 query = self.query.clone(sql.UpdateQuery) 296 298 query.add_update_values(kwargs) 297 299 query.execute_sql(None) … … 306 308 code (it requires too much poking around at model internals to be 307 309 useful at that level). 308 310 """ 311 assert self.query.can_filter(), \ 312 "Cannot update a query once a slice has been taken." 309 313 query = self.query.clone(sql.UpdateQuery) 310 314 query.add_update_fields(values) 311 315 query.execute_sql(None) -
tests/modeltests/update/models.py
63 63 >>> DataPoint.objects.values('value').distinct() 64 64 [{'value': u'thing'}] 65 65 66 We do not support update on already sliced query sets. 67 68 >>> DataPoint.objects.all()[:2].update(another_value='another thing') 69 Traceback (most recent call last): 70 ... 71 AssertionError: Cannot update a query once a slice has been taken. 72 66 73 """ 67 74 }