Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28632 closed Bug (fixed)

Manager.raw() crashes if the model has GIS fields

Reported by: gcbirzan Owned by: Sergey Fedoseev
Component: GIS Version: 2.0
Severity: Release blocker Keywords:
Cc: Sergey Fedoseev Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by gcbirzan)

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

Change History (10)

comment:1 by gcbirzan, 7 years ago

Description: modified (diff)

comment:2 by gcbirzan, 7 years ago

Version: 1.112.0

comment:3 by gcbirzan, 7 years ago

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.

comment:4 by Claude Paroz, 7 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:5 by Tim Graham, 7 years ago

Cc: Sergey Fedoseev added
Summary: Models having gis fields cannot be used with Manager.raw()Manager.raw() crashes if the model has GIS fields

comment:6 by Sergey Fedoseev, 7 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:7 by Sergey Fedoseev, 7 years ago

Has patch: set

comment:8 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 8869142a:

Fixed #28632 -- Updated docs about using raw SQL with GIS and doc'd changes from refs #28518 in release notes.

comment:10 by Tim Graham <timograham@…>, 7 years ago

In a44fb4aa:

[2.0.x] Fixed #28632 -- Updated docs about using raw SQL with GIS and doc'd changes from refs #28518 in release notes.

Backport of 8869142a4d5b069c61781c0e4c5fdc971b017949 from master

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