Django

Code

Ticket #7232 (closed: fixed)

Opened 2 months ago

Last modified 1 week ago

unexpected results and incorrectly generated SQL using OneToOne models and Postgres

Reported by: andrew@brehaut.net Assigned to: nobody
Milestone: 1.0 Component: Database wrapper
Version: SVN Keywords: qsrf-cleanup
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Attachments

Change History

06/10/08 10:02:22 changed by gav

  • keywords set to qsrf-cleanup.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

06/16/08 12:10:45 changed by jacob

  • milestone set to 1.0.

06/28/08 23:07:20 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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.


Add/Change #7232 (unexpected results and incorrectly generated SQL using OneToOne models and Postgres)




Change Properties
Action