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.
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.
Thanks for working on this!
__
Johannes
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/rpkcIupLI9gJ.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Am 12.10.2011 um 03:35 schrieb Steven Cummings:
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.
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.
Thanks for working on this!
__
Johannes
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
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
On Oct 12, 4:47 pm, Steven Cummings <estebis...@gmail.com> wrote:
Then there is the possibility that some day we could support the
UNCHANGED return value. This would be actually cheap to do if Django
would support update of only changed fields. We couldn't support that
return value if the only choices would be just 1/0 return values.
> > I agree that model.save() should never return 0/None/models.NOACTION,Agreed. The only question is: If we don't want to support the
> > 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.
>
> Possibly, but an exception cannot be added until the programmer is passing a
> precondition and can reasonable expect the condition of nothing being saved.
> That's definitely not on this ticket.
models.UPDATED / models.INSERTED return values, and we decide that 0
should not be ever returned, then why return the 1? That will be a
return value of no information. If you are not going to do the
models.UPDATED/INSERTED return value, then using up the .save() return
value should not be done at this time. We can't change the return
value at will, so we should not commit to something which doesn't have
any use now, and might not have any use ever.
My point is that we should never just return 0 if there is a
concurrent modification or some other reason for not being able to
persist the object state. Why? When you request obj.save() you are
requesting the object state to be persisted. If that can't be done,
it's an exception. delete() does not have the same problem: if you do
a delete, and the object is already deleted, then there is no problem.
The DB state is still synchronized with the delete.
The biggest problem of just returning 0 from the .save() on concurrent
modification is that if the developer forgets to do if obj.save(): ...
Also, if you just return 0, you will lose the information WHY the
object couldn't be saved, you just know it wasn't saved for some
reason.
Another way to think about this: when there is a unique constraint
violation, we raise an exception (the one from the DB backend). To be
consistent with returning 0 when the object can't be saved due to some
other reason, shouldn't we just catch that exception and return 0? Bad
idea, right?
> So, is there a good sense of "sure" or "probable" enhancements to modelsI don't think there is. For that reason I would just postpone the
> that could help us with the return API of Model.save, and whether
> QuerySet.delete should return counts that include related objects? If
> "coming enhancements" or directions for Models can concretely inform, that
> would be great.
model.save() return value decision. I feel pretty strongly that
model.save() should never return 0 in the meaning of "didn't save your
changes" (note that this is different from "there were no changes").
It is just too easy to miss that return value and have half-done
updates because of that.
Now I have the feeling that I have gone through this exact same
discussion before, and have had the exact same misunderstanding, too,
before. So, sorry for that...
> I think a reasonable option to discuss might be leaving the save() API as itI would go with immediate only, with the ability to get the counts for
> is and rolling this enhancement back to the internal code (i.e.,
> UpdateQuery, DeleteQuery) returning counts to support the prospective
> enhancements I've alluded to, and/or overrides of save(). Until there are
> any changes to save(), I agree it is not going to be useful info. However
> for delete it seems immediately usable (and then we're left with the debate
> of counting immediate-only or including related objects).
cascaded deletes per object type as a kwarg option. The kwarg option
could be left for later implementation. One reason for immediate only
is that at least PostgreSQL and MySQL does it that way for ON DELETE
CASCADE foreign keys. So, if you are getting the value from the cursor
and using ON DELETE CASCADE instead of doing the cascade in Django,
you will not get the cascade counts anyways. And even if you do the
cascade in Django, then it would be consistent with what a SQL
database would report.
So, what are core-dev thoughts on going on ahead and returning row-modified counts from Model.save() and QuerySet.update/delete?
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/cubG4FAps0oJ.
Cheers,
Florian
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/ziNdv-aRePQJ.