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-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to