Opened 65 minutes ago

Last modified 41 minutes ago

#37321 assigned Bug

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: Accepted
Has patch: no 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 (2)

comment:1 by Yassin Bahri, 41 minutes 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, 41 minutes ago

Owner: set to Yassin Bahri
Status: newassigned
Triage Stage: UnreviewedAccepted
Note: See TracTickets for help on using tickets.
Back to Top