dlamotte / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

custom SQL in TaggedItemManager.get_related() uses 'LIMIT' clause, which doesn't work on Oracle #213

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The following unit test fails on Oracle:

>>> TaggedItem.objects.get_related(l1, Link, num=1)
[<Link: link 2>]

The root cause is the 'LIMIT' clause at the end of the generated custom
SQL.  Oracle doesn't do 'LIMIT' clauses.  See
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:127412348064
(careful, it's 232 pages long!).

I'm using Django 1.0.2, Oracle XE 10g, and cx_Python 5.0.2.

The error message when running the unit tests (as divided by my patch in
issue 212) looks like this:

======================================================================
ERROR: test_get_related_objects_of_same_model_limited_number_of_results
(tagging.tests.tests.TestGetRelatedTaggedItems)
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"/home/nfs/aball/workspace/django_tagging_test_project/tagging/tests/tests.py",
line 738, in test_get_related_objects_of_same_model_limited_number_of_results
    related_objects = TaggedItem.objects.get_related(self.l1, Link, num=1)
  File
"/home/nfs/aball/workspace/django_tagging_test_project/tagging/models.py",
line 431, in get_related
    cursor.execute(query, params)
  File
"/var/lib/python-support/python2.5/django/db/backends/oracle/base.py", line
349, in execute
    raise e
DatabaseError: ORA-00933: SQL command not properly ended

----------------------------------------------------------------------

==
and the custom SQL statement generated looks like

        SELECT "TESTS_LINK"."ID", COUNT(related_tagged_item.object_id) AS
"COUNT"
        FROM "TESTS_LINK", "TAGGING_TAGGEDITEM", "TAGGING_TAG",
"TAGGING_TAGGEDITEM" related_tagged_item
        WHERE "TAGGING_TAGGEDITEM".object_id = 1
          AND "TAGGING_TAGGEDITEM".content_type_id = 12
          AND "TAGGING_TAG".id = "TAGGING_TAGGEDITEM".tag_id
          AND related_tagged_item.content_type_id = 12
          AND related_tagged_item.tag_id = "TAGGING_TAGGEDITEM".tag_id
          AND "TESTS_LINK"."ID" = related_tagged_item.object_id
          AND related_tagged_item.object_id != "TAGGING_TAGGEDITEM".object_id
        GROUP BY "TESTS_LINK"."ID"
        ORDER BY "COUNT" DESC
        LIMIT 1
==

Original issue reported on code.google.com by anb...@gmail.com on 20 Aug 2009 at 10:36

GoogleCodeExporter commented 8 years ago
Another useful link for doing something like using a 'LIMIT' clause in Oracle:

http://forums.oracle.com/forums/thread.jspa?messageID=1570364

I wonder how Django's ORM handles slicing query sets.

Original comment by anb...@gmail.com on 20 Aug 2009 at 10:37