On Oct 12, 1:37 pm, Johannes Dollinger <emulb...@googlemail.com>
wrote:
> Ticket #12086 is a duplicate. I don't think QuerySet.delete() should return 
> the number of all collected objects, but just the number of objects deleted 
> from QuerySet.model.

Agree. A way to get the counts per object type would be useful
(logging for starters). It should not be the default return value,
though...

> And Model.save()/Model.delete() should really only return 1, as *one object* 
> has been saved/deleted, even if more than one database row was touched. Thus, 
> both methods don't need the return value.

Model.delete() can easily return 0. The easiest way to get 0 is doing
the delete two times in a row. Or having a concurrent delete. The
return value costs us nothing, except if for some reason we would want
to return something else from .delete() in the future. I don't see
that happening.

Model.save() should return models.UPDATED or models.INSERTED. That is
more helpful than the 1/0 return value. For example you might want to
do different things if the model was inserted or updated in
application code. Or if loading data from a file, you might want to
know how many objects already existed in the DB and how many were
inserted. Of course if you could cheaply get models.UNCHANGED, that
would make the feature perfect...

I agree that model.save() should never return 0/None/models.NOACTION,
that should be an exception instead of a return value. After .save()
the model should exists in the database. If the object for some reason
isn't persisted, it is worth an exception instead of easy to miss
return value.

 - Anssi Kääriäinen

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to