Opened 7 years ago

Closed 7 years ago

Last modified 3 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: UI/UX:

Description

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:
        Place.objects.exclude(restaurant__isnull=True)
    Exception raised:
        Traceback (most recent call last):
          File "/usr/local/lib/python2.5/site-packages/django/test/_doctest.py", line 1267, in __run
            compileflags, 1) in test.globs
          File "<doctest modeltests.one_to_one.models.__test__.API_TESTS[41]>", line 1, in <module>
            Place.objects.exclude(restaurant__isnull=True)
          File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 43, in __repr__
            return repr(list(self))
          File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 55, in __len__
            self._result_cache.extend(list(self._iter))
          File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 162, in iterator
            for row in self.query.results_iter():
          File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 200, in results_iter
            for rows in self.execute_sql(MULTI):
          File "/usr/local/lib/python2.5/site-packages/django/db/models/sql/query.py", 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/models.py:

>>> 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 7 years ago by gav

  • Keywords qsrf-cleanup added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by jacob

  • milestone set to 1.0

comment:3 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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