[Django] #29810: Left outer join using FilteredRelation failed on empty result

17 views
Skip to first unread message

Django

unread,
Oct 1, 2018, 5:51:59 AM10/1/18
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: dvazar | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: ORM
Severity: Normal | FilteredRelation
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When I try to join table with using `FilteredRelation` clause it failed if
the result of a joined table is null.
This error can be reproduce by adding the following test case to the
corresponding
[https://github.com/django/django/blob/2.0/tests/filtered_relation/tests.py#L9
test module]:
{{{#!div style="font-size: 80%"
tests.filtered_relation.tests.FilteredRelationTests:
{{{#!python
def test_select_related_empty_join(self):
self.assertFalse(
Author.objects.annotate(
empty_join=FilteredRelation('book', condition=Q(
book__title='not existing book')),
).select_related('empty_join')
)
}}}
}}}

This bug is typical since version 2.0 and exists until now.

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

Django

unread,
Oct 1, 2018, 5:56:41 AM10/1/18
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage:
FilteredRelation | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Dmitrii Azarenko:

Old description:

> When I try to join table with using `FilteredRelation` clause it failed
> if the result of a joined table is null.
> This error can be reproduce by adding the following test case to the
> corresponding
> [https://github.com/django/django/blob/2.0/tests/filtered_relation/tests.py#L9
> test module]:
> {{{#!div style="font-size: 80%"
> tests.filtered_relation.tests.FilteredRelationTests:
> {{{#!python
> def test_select_related_empty_join(self):
> self.assertFalse(
> Author.objects.annotate(
> empty_join=FilteredRelation('book', condition=Q(
> book__title='not existing book')),
> ).select_related('empty_join')
> )
> }}}
> }}}
>
> This bug is typical since version 2.0 and exists until now.

New description:

When I try to join table with using `FilteredRelation` clause it failed if
the result of a joined table is null.
This error can be reproduce by adding the following test case to the
corresponding
[https://github.com/django/django/blob/2.0/tests/filtered_relation/tests.py#L9
test module]:
{{{#!div style="font-size: 80%"
tests.filtered_relation.tests.FilteredRelationTests:
{{{#!python
def test_select_related_empty_join(self):
self.assertFalse(
Author.objects.annotate(
empty_join=FilteredRelation('book', condition=Q(
book__title='not existing book')),
).select_related('empty_join')
)
}}}
}}}

{{{#!div style="font-size: 80%"
Error:
{{{
............E.s................
======================================================================
ERROR: test_select_related_empty_join
(filtered_relation.tests.FilteredRelationTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File
"/home/adv/projects/github/django/tests/filtered_relation/tests.py", line
46, in test_select_related_empty_join
).select_related('empty_join')
File "/usr/lib/python3.6/unittest/case.py", line 674, in assertFalse
if expr:
File "/home/adv/projects/github/django/django/db/models/query.py", line
271, in __bool__
self._fetch_all()
File "/home/adv/projects/github/django/django/db/models/query.py", line
1232, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/adv/projects/github/django/django/db/models/query.py", line
67, in __iter__
rel_populator.populate(row, obj)
File "/home/adv/projects/github/django/django/db/models/query.py", line
1876, in populate
self.local_setter(from_obj, obj)
File
"/home/adv/projects/github/django/django/db/models/sql/compiler.py", line
892, in local_setter
f.remote_field.set_cached_value(from_obj, obj)
File
"/home/adv/projects/github/django/django/db/models/fields/mixins.py", line
23, in set_cached_value
instance._state.fields_cache[self.get_cache_name()] = value
AttributeError: 'NoneType' object has no attribute '_state'

----------------------------------------------------------------------
}}}
}}}

This bug is typical since version 2.0 and exists until now.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:1>

Django

unread,
Oct 1, 2018, 10:31:38 AM10/1/18
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:2>

Django

unread,
Mar 13, 2019, 7:39:37 AM3/13/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Can Sarıgöl):

Hi, could you review this [https://code.djangoproject.com/ticket/29810
PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:3>

Django

unread,
Mar 13, 2019, 7:39:56 AM3/13/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* cc: Can Sarıgöl (added)
* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:4>

Django

unread,
Mar 13, 2019, 10:16:13 AM3/13/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


Comment:

Tests aren't passing.

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:5>

Django

unread,
Mar 13, 2019, 10:31:08 AM3/13/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Can Sarıgöl):

Sorry, I didn't think it was about PR. I'm looking at

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:6>

Django

unread,
Mar 14, 2019, 4:11:37 AM3/14/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* needs_better_patch: 1 => 0


Comment:

I hope the fails are not about me this time :)

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:7>

Django

unread,
Apr 16, 2019, 2:26:31 AM4/16/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* status: new => assigned
* owner: nobody => Can Sarıgöl


--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:8>

Django

unread,
Apr 23, 2019, 5:41:13 AM4/23/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* version: 2.0 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:9>

Django

unread,
Apr 23, 2019, 7:01:04 AM4/23/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:10>

Django

unread,
Apr 23, 2019, 8:30:49 AM4/23/19
to django-...@googlegroups.com
#29810: Left outer join using FilteredRelation failed on empty result
-------------------------------------+-------------------------------------
Reporter: Dmitrii Azarenko | Owner: Can
| Sarıgöl
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: ORM | Triage Stage: Accepted
FilteredRelation |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c00b4dbda2d9217cac205c4ffb3ccc1fa59a28ae" c00b4dbd]:
{{{
#!CommitTicketReference repository=""
revision="c00b4dbda2d9217cac205c4ffb3ccc1fa59a28ae"
Fixed #29810 -- Fixed crash of select_related() on FilteredRelation with
empty result.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29810#comment:11>

Reply all
Reply to author
Forward
0 new messages