Opened 4 weeks ago

Closed 10 days ago

Last modified 10 days ago

#37321 closed Bug (fixed)

Document the effect of setting BaseSpatialField.srid to -1

Reported by: Jacob Walls Owned by: Yassin Bahri
Component: Documentation Version: 6.1
Severity: Normal Keywords:
Cc: 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

For spatial model fields, setting a -1 srid has a special meaning, and it's tested:

class MinusOneSRID(models.Model):
    geom = models.PointField(srid=-1)  # Minus one SRID.

However, the documentation says nothing about this special meaning. It was added in #7579.

I'm suggesting we should document its effect (no SRID transform will be attempted, assigned geometries/rasters will lose any explicit srid). This would have been helpful when responding to a ​forum post where a user tried to set srid=None, which doesn't work.

Change History (7)

comment:1 by Yassin Bahri, 4 weeks ago

I reviewed the implementation, the existing documentation, and the behavior introduced in #7579. This is a valid documentation bug, and I was unable to find a duplicate ticket.

The current BaseSpatialField.srid documentation does not explain the intentional special behavior of srid=-1.

When Django prepares a geometry or raster for a database operation, BaseSpatialField.get_prep_value() sets its SRID to -1. This prevents an automatic transformation to the field's coordinate system, but it also means that the value's original explicit SRID is not preserved.

I am marking this ticket as Accepted, assigning it to myself, and will update the BaseSpatialField.srid documentation to explain this behavior clearly.

The documentation will clarify that:

  • srid=-1 disables automatic SRID transformation.
  • Geometry and raster values are assigned an SRID of -1 when prepared for database operations.
  • Any explicit SRID previously attached to the value is therefore discarded.

comment:2 by Yassin Bahri, 4 weeks ago

Owner: set to Yassin Bahri
Status: new → assigned
Triage Stage: Unreviewed → Accepted

comment:3 by Yassin Bahri, 4 weeks ago

Has patch: set

comment:4 by Jacob Walls, 4 weeks ago

Patch needs improvement: set

comment:5 by Jacob Walls, 10 days ago

Patch needs improvement: unset
Triage Stage: Accepted → Ready for checkin

comment:6 by Jacob Walls <jacobtylerwalls@…>, 10 days ago

Resolution: → fixed
Status: assigned → closed

In 85647bc:

Fixed #37321 -- Documented BaseSpatialField.srid=-1 behavior.

comment:7 by Jacob Walls <jacobtylerwalls@…>, 10 days ago

In b8f300c8:

[6.1.x] Fixed #37321 -- Documented BaseSpatialField.srid=-1 behavior.

Backport of 85647bccc19947646f5b382808415acf623e964d from main.

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