[Django] #23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error instead of the unique error message

14 views
Skip to first unread message

Django

unread,
Nov 19, 2014, 5:42:55 PM11/19/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
raratiru | Status: new
Type: | Version: 1.7
Uncategorized | Keywords: IntegrityError, Unique Constraint,
Component: GIS | Admin
Severity: Normal | Has patch: 0
Triage Stage: | UI/UX: 0
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
models.py
{{{
from django.contrib.gis.db import models as geomodels

class GeoUnique(geomodels.Model):
geo_point = geomodels.PointField(
unique=True,
srid=4326
)
geoobjects = geomodels.GeoManager()
}}}


In the admin interface, if the same PointField is entered twice, an
IntegrityError rises with a 40x Bad Request, while in any other of the
django.db.models if the unique constraint is "on" and "activated" a
friendly message notifies the user that the model instance cannot be
saved.

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

Django

unread,
Nov 20, 2014, 3:53:53 AM11/20/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: IntegrityError, | Triage Stage:
Unique Constraint, Admin | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

When quickly testing this, I was not able to reproduce the problem. Could
you provide us with a sample project to reproduce your issue? Which
backend are you using?

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

Django

unread,
Nov 20, 2014, 5:34:49 PM11/20/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: IntegrityError, | Triage Stage:
Unique Constraint, Admin | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by raratiru):

Thank you for the reply.

This repository [https://github.com/raratiru/geoDjangobug/tree/master]
represents the issue described with the minimum possible changes to the
default django installation.

Pay attention -however- to incorporate the changes intoduced by this fix
[https://github.com/django/django/pull/3451/files] which is not included
in Django 1.7 release.

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

Django

unread,
Nov 20, 2014, 5:35:10 PM11/20/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: IntegrityError, | Triage Stage:
Unique Constraint, Admin | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by raratiru):

* cc: raratiru (added)


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

Django

unread,
Nov 21, 2014, 3:40:56 AM11/21/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: closed

Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: IntegrityError, | worksforme
Unique Constraint, Admin | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

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


Comment:

Thanks for the sample project, was really useful to debug the issue.

As you are manually building the Point object in your custom save()
method, the admin cannot detect magically that the point is a duplicate.
In your case, you could solve this by adding a `unique_together =
('longitude', 'latitude')` index to your model, or by providing a custom
`ModelForm` for your admin and creating the point in the form before the
unique validation. (Note that your model is not ideal in that it
duplicates data in the database, but that's another issue.)

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

Django

unread,
Nov 21, 2014, 8:13:57 AM11/21/14
to django-...@googlegroups.com
#23874: Admin Interface: Unique constraint in gis.db.models raises Integrity Error
instead of the unique error message
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: closed
Component: GIS | Version: 1.7
Severity: Normal | Resolution:
Keywords: IntegrityError, | worksforme
Unique Constraint, Admin | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by raratiru):

Thank you for the very useful the solutions provided in this post. I will
try to delineate the method I use to create a PointField in the admin,
since I am actually trying to enter an address and automatically save the
coordinates.

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

Reply all
Reply to author
Forward
0 new messages