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.
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).