Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#12721 closed (fixed)

PostgreSQL problem deleting objects with GenericRelation and non-integer object_id

Reported by: Karen Tracey Owned by: Carl Meyer
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: ramusus@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Follow-on from #10015. Failing test case attached. Failure is:

======================================================================
ERROR: test_charlink_delete (regressiontests.generic_relations_regress.tests.GenericRelationTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kmt/django/trunk/tests/regressiontests/generic_relations_regress/tests.py", line 37, in test_charlink_delete
    oddrel.delete()
  File "/home/kmt/django/trunk/django/db/models/base.py", line 604, in delete
    delete_objects(seen_objs, using)
  File "/home/kmt/django/trunk/django/db/models/query.py", line 1275, in delete_objects
    del_query.delete_batch_related(pk_list, using=using)
  File "/home/kmt/django/trunk/django/db/models/sql/subqueries.py", line 65, in delete_batch_related
    self.do_query(f.m2m_db_table(), where, using=using)
  File "/home/kmt/django/trunk/django/db/models/sql/subqueries.py", line 27, in do_query
    self.get_compiler(using).execute_sql(None)
  File "/home/kmt/django/trunk/django/db/models/sql/compiler.py", line 740, in execute_sql
    cursor.execute(sql, params)
ProgrammingError: operator does not exist: character varying = integer
LINE 1: ...ic_relations_regress_charlink" WHERE ("object_id" IN (1) AND...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.


======================================================================
ERROR: test_textlink_delete (regressiontests.generic_relations_regress.tests.GenericRelationTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kmt/django/trunk/tests/regressiontests/generic_relations_regress/tests.py", line 42, in test_textlink_delete
    oddrel.delete()
  File "/home/kmt/django/trunk/django/db/models/base.py", line 604, in delete
    delete_objects(seen_objs, using)
  File "/home/kmt/django/trunk/django/db/models/query.py", line 1275, in delete_objects
    del_query.delete_batch_related(pk_list, using=using)
  File "/home/kmt/django/trunk/django/db/models/sql/subqueries.py", line 65, in delete_batch_related
    self.do_query(f.m2m_db_table(), where, using=using)
  File "/home/kmt/django/trunk/django/db/models/sql/subqueries.py", line 27, in do_query
    self.get_compiler(using).execute_sql(None)
  File "/home/kmt/django/trunk/django/db/models/sql/compiler.py", line 740, in execute_sql
    cursor.execute(sql, params)
ProgrammingError: operator does not exist: text = integer
LINE 1: ...ic_relations_regress_textlink" WHERE ("object_id" IN (1) AND...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.


----------------------------------------------------------------------
Ran 4 tests in 0.557s

FAILED (errors=2)

No idea where the fix belongs.

Attachments (2)

oddrel.diff (2.1 KB ) - added by Karen Tracey 15 years ago.
12721_r12344.diff (3.4 KB ) - added by Carl Meyer 15 years ago.

Download all attachments as: .zip

Change History (6)

by Karen Tracey, 15 years ago

Attachment: oddrel.diff added

comment:1 by ramusus, 15 years ago

Cc: ramusus@… added

by Carl Meyer, 15 years ago

Attachment: 12721_r12344.diff added

comment:2 by Carl Meyer, 15 years ago

Has patch: set
Owner: changed from nobody to Carl Meyer
Status: newassigned

Appears to me that this (unlike #10015) is actually a contenttypes-specific issue. It only occurs if a field containing a foreign PK for a relation has a different database column type from the PK field it's pointing to, and AFAICT GenericRelation is the only case where this can happen: ForeignKey and ManyToManyField always use the correct column type. I can't recreate the problem without a GenericRelation involved.

Fix attached that ensures the get_db_prep_value method from the appropriate field is called for the PKs before the query goes to the database. All tests pass for me on Postgres (barring unrelated failures from #12692 and #12724).

comment:3 by Karen Tracey, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [12353]) Fixed #12721: Ensured objects with generic relations that use non-integer object ID fields can be deleted on PostgreSQL. Thanks much carljm for patch and Russ for review.

comment:4 by Karen Tracey, 15 years ago

(In [12356]) [1.1.X] Really this time -- fixed #12721: Ensured objects with generic relations that use non-integer object ID fields can be deleted on PostgreSQL. Thanks much carljm for patch and Russ for review.

Remainder of r12353 from trunk, previous attempt only picked up the new tests.

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