[Django] #34376: Admin has no support for unique constraint fields (while using SQLite?)

4 views
Skip to first unread message

Django

unread,
Mar 1, 2023, 8:58:42 AM3/1/23
to django-...@googlegroups.com
#34376: Admin has no support for unique constraint fields (while using SQLite?)
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: nobody
Urbanowicz |
Type: | Status: new
Uncategorized |
Component: | Version: 4.1
contrib.admin |
Severity: Normal | Keywords: sqlite unique admin
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The context is an Admin based application - all database operations are
done using Admin. The backend is SQLite.
One of the fields in the application is a field for an (unique) ip
address:
`ip = models.GenericIPAddressField(protocol='IPv4', unique=True)`

When there's an append to enter duplicate IP address, the application
crashes to a 500 error:

`django.db.utils.IntegrityError: UNIQUE constraint failed: <table>.ip`

Attempt at handling that error by catching the exception and emitting an
message leads to another error:

`django.db.transaction.TransactionManagementError: An error occurred
in the current transaction. You can't execute queries until the end of the
'atomic' block.`

I would expect that, since the ORM supports unique fields, there's some
Admin UI to handle constraint errors in a similar way to validation
errors, and not fall flat and give the user a 500 error.

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

Django

unread,
Mar 1, 2023, 9:00:15 AM3/1/23
to django-...@googlegroups.com
#34376: Admin has no support for unique constraint fields (while using SQLite?)
-------------------------------------+-------------------------------------
Reporter: Alex Urbanowicz | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 4.1
Severity: Normal | Resolution:

Keywords: sqlite unique admin | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> The context is an Admin based application - all database operations are
> done using Admin. The backend is SQLite.
> One of the fields in the application is a field for an (unique) ip
> address:
> `ip = models.GenericIPAddressField(protocol='IPv4', unique=True)`
>
> When there's an append to enter duplicate IP address, the application
> crashes to a 500 error:
>
> `django.db.utils.IntegrityError: UNIQUE constraint failed:
> <table>.ip`
>
> Attempt at handling that error by catching the exception and emitting an
> message leads to another error:
>
> `django.db.transaction.TransactionManagementError: An error occurred
> in the current transaction. You can't execute queries until the end of
> the 'atomic' block.`
>
> I would expect that, since the ORM supports unique fields, there's some
> Admin UI to handle constraint errors in a similar way to validation
> errors, and not fall flat and give the user a 500 error.

New description:

The context is an Admin based application - all database operations are
done using Admin. The backend is SQLite.
One of the fields in the application is a field for an (unique) ip
address:
`ip = models.GenericIPAddressField(protocol='IPv4', unique=True)`

When there's an attempt to enter duplicate IP address, the application


crashes to a 500 error:

`django.db.utils.IntegrityError: UNIQUE constraint failed: <table>.ip`

Attempt at handling that error by catching the exception and emitting an
message leads to another error:

`django.db.transaction.TransactionManagementError: An error occurred
in the current transaction. You can't execute queries until the end of the
'atomic' block.`

I would expect that, since the ORM supports unique fields, there's some
Admin UI to handle constraint errors in a similar way to validation
errors, and not fall flat and give the user a 500 error.

--

Comment (by Alex Urbanowicz):

s/append/attempt/

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

Reply all
Reply to author
Forward
0 new messages