[Django] #29315: exclude with OneToOneField produces incorrect results on sqlite

2 views
Skip to first unread message

Django

unread,
Apr 11, 2018, 5:36:05 AM4/11/18
to django-...@googlegroups.com
#29315: exclude with OneToOneField produces incorrect results on sqlite
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
RaphaelKimmig |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When excluding instances where the related model has a certain field value
instances where no related model exists are excluded as well. This happens
with sqlite 3.16.2 on mac os.

Using postgresql with psycopg2 I was unable to reproduce the issue.

{{{
from django.db import models


class A(models.Model):
pass


class B(models.Model):
a = models.OneToOneField(A)
value = models.IntegerField()


def test():
A.objects.all().delete()
B.objects.all().delete()

A.objects.create()
assert A.objects.exclude(b__value=12345).count() == 1, "We expect to
get one A but got zero."
}}}

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

Django

unread,
Apr 11, 2018, 10:42:50 AM4/11/18
to django-...@googlegroups.com
#29315: exclude with OneToOneField produces incorrect results on sqlite
-------------------------------------+-------------------------------------
Reporter: Raphael Kimmig | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Tim Graham):

I can't reproduce the issue give what you provided. Can you do any further
investigation such as checking the query that Django generates? Not sure
if it could be a bug in your particular version of SQLite.

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

Django

unread,
Apr 11, 2018, 11:32:20 AM4/11/18
to django-...@googlegroups.com
#29315: exclude with OneToOneField produces incorrect results on sqlite
-------------------------------------+-------------------------------------
Reporter: Raphael Kimmig | Owner: nobody
Type: Bug | Status: new

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

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

Comment (by Raphael Kimmig):

I just tried reproducing the bug on Debian 9 and I can't.
I'm running mac os 10.12.6 on the affected machine.

The query produced looks fine:
{{{
SELECT "bar_a"."id" FROM "bar_a" LEFT OUTER JOIN "bar_b" ON ("bar_a"."id"
= "bar_b"."a_id") WHERE NOT ("bar_b"."value" = 12345 AND "bar_b"."value"
IS NOT NULL) LIMIT 21
}}}

sqlite version on the affected mac:

{{{
sqlite3.version
>>> '2.6.0'
sqlite3.sqlite_version
>>> '3.23.0'
}}}

Is there anything else that might be helpful?

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

Django

unread,
Apr 11, 2018, 11:43:25 AM4/11/18
to django-...@googlegroups.com
#29315: exclude with OneToOneField produces incorrect results on sqlite
-------------------------------------+-------------------------------------
Reporter: Raphael Kimmig | Owner: nobody
Type: Bug | Status: closed

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

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

* status: new => closed
* resolution: => invalid


Comment:

I noticed "Fix two problems in the new LEFT JOIN strength reduction
optimization." in the [https://sqlite.org/changes.html#version_3_23_1
SQLite 3.23.1 release notes] which looks like it could be the cause.

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

Reply all
Reply to author
Forward
0 new messages