@Dave Gaeddert
Since you mentioned it - what should a get_or_none method do about
multiple objects? Still raise? Silently "cast" to None (imho
semantically wrong)? Return the underlying queryset (or any other
"multiple objects container thingy")?
The problem with .get() is - it may end in 3 different states (tristate
- None, one object, multiple objects), where only one state is the
expected case. To me handling the other unexpected ones as exceptions
seems to be a very common pattern in python (thus also newbies should be
able to handle it properly in their code).
Now a .get_or_none() would shift the "good results" to (None, one
object) still leaving multiple objects out. Did we gain here anything?
Not if multiple objects is still within reach (eg. uniqueness cannot be
assumed from the filter conditions) - ppl would still have to write
exception handling code. Just forgetting that is like a time bomb that
might go off anytime a project aggregates more production data (welcome
to error 500 websites / dying servers).
But if .get_or_none() would handle multiple objects without raising (eg.
returning the queryset) - we haven't gained anything either, we just
surfaced the fact, that .get is only a convenient function on top of
filtered search queries. And ppl still have to deal with the tristate
result in their code.
Maybe I am overlooking something - currently I dont see, how any of that
might be helpful in terms of easier API usage.
Am 23.06.22 um 16:57 schrieb Dave Gaeddert:
> --
> You received this message because you are subscribed to the Google
> Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
django-develop...@googlegroups.com
> <mailto:
django-develop...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-developers/c9833cf7-6113-4405-b5e6-8de2dda1fdb6n%40googlegroups.com
> <
https://groups.google.com/d/msgid/django-developers/c9833cf7-6113-4405-b5e6-8de2dda1fdb6n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
netzkolchose.de UG (haftungsbeschränkt)
Geschäftsführer: Jörg Breitbart
Handelsregister: HRB 504791 Amtsgericht Jena
Steuer-Nr.: 161/115/07450
USt-IdNr.: DE268234065