[Django] #33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a feature

3 views
Skip to first unread message

Django

unread,
May 25, 2022, 5:42:36 AM5/25/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
--------------------------------------+------------------------
Reporter: Samir Shah | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
The [https://datatracker.ietf.org/doc/html/rfc7946#section-3.2 GeoJSON
specification] says:

If a Feature has a commonly used identifier, that identifier SHOULD be
included as a member of the Feature object with the name "id", and the
value of this member is either a JSON string or number.

Thus it should be possible to generate a GeoJSON object which looks like
this:

{{{
{
"type": "Feature",
"id": 24
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [8.11, 52.11]
}
}
}}}

`django.contrib.gis.serializers.geojson.Serializer` doesn't support this -
it's not possible to add an `id` key to a feature without overriding the
`get_dump_object()` method of the class. If you specify `pk` in the
fields, then this gets added to the `properties` of the feature, but not a
top level `id` field. Having an ID is important for a number of use cases
- particularly when GeoJSON data is made editable via an API, for which
many client libraries use the `id` to uniquely identify features.

Given that the specification says an `id` SHOULD be present if available,
I would like to propose one of the following:

1. Django defaults to using the object PK as the `id` for the feature.

2. Or, if (1) is considered a backwards-incompatible change, then a
mechanism is provided to instruct the class to include an ID (which I
guess may not always be the the primary key)

I'm happy to contribute a PR for this if you can give me guidance on what
the preferred approach would be. Personally I think Django should include
the ID by default.

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

Django

unread,
May 25, 2022, 6:16:19 AM5/25/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
-----------------------------+--------------------------------------

Reporter: Samir Shah | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: dev
Severity: Normal | Resolution:

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

* cc: Claude Paroz (added)
* type: Bug => New feature


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

Django

unread,
May 28, 2022, 3:14:10 AM5/28/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
-----------------------------+------------------------------------
Reporter: Samir Shah | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

Sure, a patch would be welcome!

--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:2>

Django

unread,
May 28, 2022, 5:36:35 AM5/28/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
-----------------------------+--------------------------------------
Reporter: Samir Shah | Owner: Samir Shah
Type: New feature | Status: assigned

Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Samir Shah):

* owner: nobody => Samir Shah
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15740 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:3>

Django

unread,
Jun 1, 2022, 7:21:39 AM6/1/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
-----------------------------+---------------------------------------------

Reporter: Samir Shah | Owner: Samir Shah
Type: New feature | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:4>

Django

unread,
Jun 1, 2022, 2:17:13 PM6/1/22
to django-...@googlegroups.com
#33742: GeoJSON serializer doesn't provide a mechanism to include the ID of a
feature
-----------------------------+---------------------------------------------
Reporter: Samir Shah | Owner: Samir Shah
Type: New feature | Status: closed
Component: GIS | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"6f73eb9d90cfec684529aab48d517e3d6449ba8c" 6f73eb9]:
{{{
#!CommitTicketReference repository=""
revision="6f73eb9d90cfec684529aab48d517e3d6449ba8c"
Fixed #33742 -- Added id to GeoJSON serializer.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:5>

Reply all
Reply to author
Forward
0 new messages