Opened 2 months ago

Closed 3 weeks ago

Last modified 3 weeks 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 Changed 2 months ago by gcbirzan

Description: modified (diff)

comment:2 Changed 2 months ago by gcbirzan

Version: 1.112.0

comment:3 Changed 2 months ago by gcbirzan

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 Changed 2 months ago by Claude Paroz

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:5 Changed 2 months ago by Tim Graham

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 Changed 2 months ago by Sergey Fedoseev

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:7 Changed 3 weeks ago by Sergey Fedoseev

Has patch: set

comment:8 Changed 3 weeks ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:9 Changed 3 weeks ago by Tim Graham <timograham@…>

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 Changed 3 weeks ago by Tim Graham <timograham@…>

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