﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28632	Models having gis fields cannot be used with Manager.raw()	gcbirzan	nobody	"This bug was introduced in [https://github.com/django/django/commit/1a85b07bddbf43da00311bdbb3ef5519a3165dc6 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)."	Bug	new	GIS	1.11	Normal				Unreviewed	0	0	0	0	0	0
