Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#7232 closed (fixed)

unexpected results and incorrectly generated SQL using OneToOne models and Postgres

Reported by: andrew@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qsrf-cleanup
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have been trying to select all the objects that do not have an associated OneToOne field.

  • M.objects.filter fails to select the correct objects - either selects everything or nothing.
  • M.objects.exclude generates incorrect SQL - missing the table name, eg:
    Failed example:
    Exception raised:
        Traceback (most recent call last):
          File "/usr/local/lib/python2.5/site-packages/django/test/", line 1267, in __run
            compileflags, 1) in test.globs
          File "<doctest modeltests.one_to_one.models.__test__.API_TESTS[41]>", line 1, in <module>
          File "/usr/local/lib/python2.5/site-packages/django/db/models/", line 43, in __repr__
            return repr(list(self))
          File "/usr/local/lib/python2.5/site-packages/django/db/models/", line 55, in __len__
          File "/usr/local/lib/python2.5/site-packages/django/db/models/", line 162, in iterator
            for row in self.query.results_iter():
          File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/", line 200, in results_iter
            for rows in self.execute_sql(MULTI):
          File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/", line 1466, in execute_sql
            cursor.execute(sql, params)
        ProgrammingError: syntax error at or near "WHERE"
        LINE 1: ...N (SELECT "one_to_one_restaurant"."place_id" FROM WHERE "one...

The following are additional cases for the unit tests in modeltests/one_to_one/

>>> p3 = Place.objects.create(name="Not A Restaurant", address="123 Fake St")
>>> Place.objects.filter(restaurant__exact=None)
[<Place: Not A Restaurant the place>]
>>> Place.objects.filter(restaurant__isnull=True)
[<Place: Not A Restaurant the place>]
>>> Place.objects.filter(restaurant__isnull=False)
[<Place: Demon Dogs the place>, <Place: Ace Hardware the place>]
>>> Place.objects.exclude(restaurant__isnull=True)
[<Place: Demon Dogs the place>, <Place: Ace Hardware the place>]
>>> Place.objects.exclude(restaurant__isnull=False)
[<Place: Not A Restaurant the place>]

I am using Ubuntu 7.10, Python 2.5.1, post QSRF Trunk Django, and Postgres 8.1

Change History (4)

comment:1 Changed 11 years ago by George Vilches

Keywords: qsrf-cleanup added

comment:2 Changed 11 years ago by Jacob

milestone: 1.0

comment:3 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

I cannot repeat this problem with current trunk. I went back as far as [7764] and it still always returned the right things in the above queries.

Please reopen if you're still seeing a problem here, but I think it must have been fixed at some point in the interim. A patch against tests/one_to_one_regress/ that demonstrates the problem would be appreciated if it does still occur.

comment:4 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top