[Django] #32972: Django ORM raw query not playing nice with Geometric Point objects

8 views
Skip to first unread message

Django

unread,
Jul 29, 2021, 4:12:06 PM7/29/21
to django-...@googlegroups.com
#32972: Django ORM raw query not playing nice with Geometric Point objects
-------------------------------------+-------------------------------------
Reporter: Donovan | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 3.2
Severity: Normal | Keywords: ORM raw query
Triage Stage: | geometric location point
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using <Object>.objects.all() the behavior works as intended and I am
able to get the Geometric Point object with the latitude and longitude
correct.
When using <Object>.objects.raw() the Point object has incorrect latitude
and longitude -- it has scientific notation and completely different
numbers.

--
Ticket URL: <https://code.djangoproject.com/ticket/32972>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 29, 2021, 4:13:32 PM7/29/21
to django-...@googlegroups.com
#32972: Django ORM raw query not playing nice with Geometric Point objects
-------------------------------------+-------------------------------------
Reporter: Donovan | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 3.2
Severity: Normal | Resolution:

Keywords: ORM raw query | Triage Stage:
geometric location point | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Donovan):

* Attachment "incorrect Point objects.png" added.

Showing what the point objects look like with a <object>.objects.raw()
query look like when doing a print(vars(object))

Django

unread,
Jul 29, 2021, 4:14:16 PM7/29/21
to django-...@googlegroups.com
#32972: Django ORM raw query not playing nice with Geometric Point objects
-------------------------------------+-------------------------------------
Reporter: Donovan | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 3.2
Severity: Normal | Resolution:

Keywords: ORM raw query | Triage Stage:
geometric location point | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Donovan):

* Attachment "expected location after serializing.png" added.

What the the Point object should have for latitude and longitude

Django

unread,
Jul 30, 2021, 12:13:06 AM7/30/21
to django-...@googlegroups.com
#32972: Django ORM raw query not playing nice with Geometric Point objects
-------------------------------------+-------------------------------------
Reporter: Donovan | Owner: nobody
Type: Bug | Status: closed
Component: GIS | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: ORM raw query | Triage Stage:
geometric location point | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Using `.raw()` is a last resort. Django takes a raw SQL query, executes
it, and returns results (as documented), it will not automatically add any
data conversion to columns. Geometry columns returned by the ORM are
wrapped with db-specific functions, e.g. `%s::bytea` on PostgreSQL or
`SDO_UTIL.TO_WKBGEOMETRY(%s)` on Oracle.

If you're having trouble understanding how Django works, see
TicketClosingReasons/UseSupportChannels for ways to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/32972#comment:1>

Reply all
Reply to author
Forward
0 new messages