Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#34376 closed Bug (worksforme)

Admin has no support for unique constraint fields.

Reported by: Alex Urbanowicz Owned by: nobody
Component: contrib.admin Version: 4.1
Severity: Normal Keywords: sqlite unique admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Urbanowicz)

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.

Attachments (1)

simplescreenrecorder-2023-03-01_19.13.17.mp4 (111.2 KB ) - added by Mariusz Felisiak 19 months ago.

Download all attachments as: .zip

Change History (3)

comment:1 by Alex Urbanowicz, 19 months ago

Description: modified (diff)

s/append/attempt/

comment:2 by Mariusz Felisiak, 19 months ago

Resolution: worksforme
Status: newclosed
Summary: Admin has no support for unique constraint fields (while using SQLite?)Admin has no support for unique constraint fields.
Type: UncategorizedBug

Thanks for the report, however it works for me, see simplescreenrecorder-2023-03-01_19.13.17.mp4.

Last edited 19 months ago by Mariusz Felisiak (previous) (diff)

by Mariusz Felisiak, 19 months ago

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