#34728: OR operator on queryset does not work as expected
-------------------------------------+-------------------------------------
     Reporter:  Kbleser              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  queryset OR          |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by René Fleschenberg):

 Hi,

 Replying to [comment:10 Natalia Bidart]:
 > I'm taking a look at this again. For the sake of clarity, René or the
 reporter, could you please paste here the test method (or any other needed
 diff) that produce a failure? I've cloned the repo and played a bit with
 the existing `find_similar_recipes` and I'm not being able to reproduce
 the issue. Thanks!

 I suspect you looked at the {{{main}}} branch, which doesn't show the
 problem :) Sorry, I should have explicitly mentioned the branch here. If
 you checkout the branch {{{queryset_problem}}} and run the tests, you
 should see that the test in {{{recipes/tests/test_models.py}}} is failing:
 https://github.com/Inglorious-
 Inge/Kochbuch2/blob/queryset_problem/recipes/tests/test_models.py

 (Not pasting the test setup here for the sake of brevity).

 {{{#!python
     def test_find_similar_recipes(self):
         similar_recipes = self.recipe.find_similar_recipes()
         self.assertEquals(len(similar_recipes), 1)
 }}}

 The reason is that in {{{recipes/models.py}}} on line 39
 (https://github.com/Inglorious-
 Inge/Kochbuch2/blob/queryset_problem/recipes/models.py#L39C4-L39C106), {{{
 at_least_four_shared_ingredients |
 same_tag_and_at_least_two_shared_ingredients}}} results in a queryset that
 turns out empty when evaluated. If you use a debugger to take a look at
 the two querysets being ORed together, you should see that
 {{{same_tag_and_at_least_two_shared_ingredients}}} by itself evaluates to
 a non-empty queryset.


 > >BTW, on Discord, there has been another report about qs1 | qs2 and qs2
 | qs1 not being equivalent, which they should be according to the docs.
 >
 > Do you have an example or link to the discussion at hand? Perhaps we
 could clarify in the docs what "equivalent" mean, in that, given that `|`
 is not commutative, it may be the case that the generated `SQL` return
 different results but still equivalent, no? :thinking:

 I really don't know what "equivalent" would mean in regards to SQL queries
 if they do not return the same set of rows :) I suspect we thought so far
 that equivalency would be guaranteed but it is actually not (if the report
 on Discord is correct).  I'll try to find the discussion on Discord and
 open a separate ticket for this, since I think it is a separate different
 issue.

 Thanks!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34728#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189921b82e1-d15546c5-44a1-4934-8954-d33ab1ddf139-000000%40eu-central-1.amazonses.com.

Reply via email to