Opened 53 minutes ago

Last modified 26 minutes ago

#37324 assigned New feature

Cannot assign expressions to spatial fields

Reported by: Jacob Walls Owned by: Md. Saikat Islam
Component: GIS Version: dev
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

SpatialProxy is too strict in the types it allows to be assigned to spatial fields -- it should allow expressions (if it can be implemented simply enough).

See fiddle:

from django.contrib.gis.db.models import PointField
from django.db import models

class Employee(models.Model):
    home = PointField()
    work = PointField()

def run():
    instance = Employee.objects.create(
        home="POINT(1 1)", work="POINT(2 2)"
    )
    # Work from home.
    instance.work = models.F("home")
    instance.save()
  File "/usr/local/lib/python3.12/site-packages/django/contrib/gis/db/models/proxy.py", line 82, in __set__
    raise TypeError(
TypeError: Cannot set Employee SpatialProxy (POINT) with value of type: <class 'django.db.models.expressions.F'>

Marking new feature, as we should document that we added support.

Change History (3)

comment:1 by Md. Saikat Islam, 27 minutes ago

I was able to reproduce the reported TypeError with F("home") assigned to a PointField. I'll work on a fix to allow expressions to be assigned to spatial fields.

comment:2 by Md. Saikat Islam, 26 minutes ago

Triage Stage: UnreviewedAccepted

comment:3 by Md. Saikat Islam, 26 minutes ago

Owner: set to Md. Saikat Islam
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top