#14373: annotate() will gladly delete your data
-----------------------------+----------------------------------------------
Reporter: patrys | Owner:
Status: new | Milestone:
Component: ORM aggregation | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
-----------------------------+----------------------------------------------
Consider the following example:
{{{
class Foo(models.Model):
name = models.CharField(max_length=100)
class Bar(models.Model):
name = models.CharField(max_length=100)
foos = models.ManyToManyField(Foo, related_name='bars')
}}}
Create your database, fill it with important data, then do the following:
{{{
bars = Bar.objects.all().annotate(foos=Sum('foos'))
}}}
Now all your data connections are gone. Yay.
What happens is that {{{annotate}}} gladly accepts "foos" even if that
attribute name is already taken. It then retrieves all the objects from
the result set and proceeds to destroy your data by assigning aggregated
values to your precious related manager. The manager then happily swallows
the integer it receives and goes to delete all the relations.
Possible fixes:
* Make {{{annotate}}} call {{{delattr}}} before calling {{{setattr}}}
* Make {{{annotate}}} raise an exception when passed an already existing
attribute
Also:
* Make the many-to-many manager think for a while before it accepts 5 or
any other integer as the new relation set
--
Ticket URL: <http://code.djangoproject.com/ticket/14373>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.