sorry if this is a stupid question, but after having read https://code.djangoproject.com/ticket/5763 and the discussions linked from it, why should __ne not be implemented?
--
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.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5cb90d5f-8683-4a34-9c15-f06bb23e6eee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAEE%2BrGopLJaRL6%3D8uafjBoAjkcFO9DuRaDXeBD6M6oWNFoADiQ%40mail.gmail.com.
8 years later, I still think we should figure out how to make exclude() do what people expect it to do, rather than implement another lookup type that overlaps with it.
With all due respect, looking through the ticket and reading responses shows me that the 'pro' side has good use cases for __ne, and the 'con' side basically says "use exclude" or "a core committer close the ticket, stop opening it" with no good reasoning or rationale behind it.
Hi Marten,
Am 2015-11-21 um 11:53 schrieb Marten Kenbeek:
The 'con' side argument is that it would create in inconsistency in the
API, since we don't have any other negated lookups either. If we can get
the same behaviour by fixing the current API, Django should not
introduce an unnecessary consistency.
I think that this is where the communication problem is:
The "con" side seems to see a problem in the current API regarding exclude() (personally, about what it is I only have a vague idea from older linked discussions: NOT(...) vs. "proper" negation) and argues that fixing the problem solves the issue and avoids inconsistency in the API brought by the introduction of __ne.
The "pro" side sees a problem in functionality when __ne is lacking, and cannot see how the "con" side's arguments would help. The problem in functionality is detailed in https://code.djangoproject.com/ticket/5763#comment:14, which essentially quotes (possibly an older version of) https://docs.djangoproject.com/en/1.8/topics/db/queries/#spanning-multi-valued-relationships and shows a related example where exclude() cannot replace __ne. As we/I cannot see how fixing/changing exclude() would help in this situation, we keep asking about __ne. ;-)
In summary, the imaginary query of comment 14
Blog.objects.filter(entry__tag__name='django', entry__author_count__ne=2)
seems quasi not be possible to implement in today's Django (but probably with your suggestion below).
Anyway, with the new lookup API, it has become trivial for any project
to implement the __ne lookup. It is the first example in the how-to
guide: https://docs.djangoproject.com/en/dev/howto/custom-lookups/#a-simple-lookup-example.
Thanks, I'll definitively check and try this out, I didn't know it before!
Best regards,
Carsten
--
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.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/565054EA.40508%40cafu.de.
--
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.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8d31a6bf-f435-4579-936b-3206c2c7c2e7%40googlegroups.com.
Hi Anssi,
Am 2015-11-21 um 12:50 schrieb Anssi Kääriäinen:
In summary, the imaginary query of comment 14
Blog.objects.filter(entry__tag__name='django',
entry__author_count__ne=2)
This isn't a real query. There isn't a field author_count, the query
needs an annotation somewhere. So, I don't think this argument is
convincing without the annotation (note that the place of the annotation
matters). In addition, providing example data and the expected results
would be great, too.
Well, yes, this is a fictional example, but if you replace author_count by some valid field that doesn't require an annotation, e.g. author__name, the (imaginary) query should be valid (for the purpose of demonstrating the problem)?
The key issue is really this, quoted from the linked Django documentation:
"To handle both of these situations, Django has a consistent way of processing
filter() calls. Everything inside a single filter() call is applied
simultaneously to filter out items matching all those requirements. Successive
filter() calls further restrict the set of objects, but for multi-valued
relations, they apply to any object linked to the primary model, not
necessarily those objects that were selected by an earlier filter() call."
That is, sometimes we *have* to put several filters into a single filter() call to obtain the desired set. If such a situation requires a negation, exclude() cannot help, because "[...], they apply to *any* object linked to the primary model, not necessarily those objects that were selected by an earlier filter() call".
The discussion seems to miss a real definition of what exactly the ne
lookup should do. There are two ways to implement ne, one is as a
complement of exact, another is as the != operator. In SQL the first one
is "col != val OR col IS NULL", the latter one is just "col != val".
Thanks for pointing this out, I wasn't aware of this (in this context) before. It seems to be another facet in the overall problem, but independent from the above, isn't it? (In my normal, "non-negated" queries, where required I account for NULLs explicitly all the time...)
Best regards,
Carsten
--
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.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/56506174.4050609%40cafu.de.