This bug was introduced in 1a85b07bddbf43da00311bdbb3ef5519a3165dc6 (I found it with git bisect). Trying to do this results in:
======================================================================
ERROR: test_17_raw_query (gis_tests.relatedapp.test_new.RelatedGeoModelTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/gcbirzan/PycharmProjects/django/tests/gis_tests/relatedapp/test_new.py", line 10, in test_17_raw_query
list(raw)
File "/home/gcbirzan/PycharmProjects/django/django/db/models/query.py", line 1234, in __iter__
for values in query:
File "/home/gcbirzan/PycharmProjects/django/django/db/models/sql/compiler.py", line 949, in apply_converters
value = converter(value, expression, connection)
File "/home/gcbirzan/PycharmProjects/django/django/contrib/gis/db/backends/postgis/operations.py", line 395, in <lambda>
return lambda value, expression, connection: None if value is None else GEOSGeometry(read(value))
File "/home/gcbirzan/PycharmProjects/django/django/contrib/gis/geos/prototypes/io.py", line 153, in read
return wkb_reader_read_hex(self.ptr, wkb, len(wkb))
File "/home/gcbirzan/PycharmProjects/django/django/contrib/gis/geos/libgeos.py", line 164, in __call__
return self.func(*args, **kwargs)
File "/home/gcbirzan/PycharmProjects/django/django/contrib/gis/geos/prototypes/threadsafe.py", line 55, in __call__
return self.cfunc(self.thread_context.handle.ptr, *args)
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type
----------------------------------------------------------------------
the test I'm using is:
from django.test import TestCase
from .models import Location
class RelatedGeoModelTest(TestCase):
fixtures = ['initial']
def test_17_raw_query(self):
raw = Location.objects.raw("SELECT * FROM {}".format(Location._meta.db_table))
list(raw)
This is on python 3.6.3rc1 with libgdal 2.2.1+dfsg-2+b2 (debian sid).
As an obvious comment, doing
SELECT id, point::bytea FROM {}
works. But, that should either be documented, or maybe the optimisation disabled for raw queries.