[Django] #29915: Admin search for UUID with dashes works only on Postgres

22 views
Skip to first unread message

Django

unread,
Nov 2, 2018, 10:02:55 AM11/2/18
to django-...@googlegroups.com
#29915: Admin search for UUID with dashes works only on Postgres
-----------------------------------------+----------------------------
Reporter: washeck | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Keywords: uuid admin
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+----------------------------
We have Django 2.1 project with model admin which includes an `UUIDField`
in `list_display` and `search_fields`. The UUID is displayed with dashes
on changelist (e.g. "245ba2eb-6852-47be-82be-7dc07327cf9e") and if the
user cut'n'paste it to the search field, I would expect admin to find it.

This works however only on Postgres but fails on Oracle. I can understand
why this happens (Oracle backend stores uuid as string) and I believe I
can workaround it by customizing `get_search_results` but I think should
be internal thing that Django handles gracefully - search should be
possible by the value as displayed in admin.

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

Django

unread,
Nov 3, 2018, 11:03:09 AM11/3/18
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Bug => Cleanup/optimization
* component: contrib.admin => Database layer (models, ORM)
* stage: Unreviewed => Accepted


Comment:

This isn't really an admin issue but rather it's due to the fact that the
default admin lookup uses `__icontains`. You could fix the issue by using
`search_fields = ['uuidfield__exact']` (adding `__exact`) although that
doesn't allow searching for part of the UUID value.

I'll tentatively accept the ticket to allow
`QuerySet.objects.filter(uuidfield__icontains='...')` to work with values
with or without dashes

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

Django

unread,
Nov 5, 2018, 5:28:14 AM11/5/18
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted

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

Comment (by Václav Řehák):

Thank you for the quick answer. However, the proposed solution does not
work as changing the uuid lookup to exact causes an error when searching
for any string other than valid uuid value.

I get ValidationError raised from UUIDField.to_python()


{{{
File "/home/vaclav/.local/share/virtualenvs/aaa-yRfablWV/lib/python3.7
/site-packages/django/db/models/fields/__init__.py" in to_python
2325. return uuid.UUID(value)

File "/usr/lib/python3.7/uuid.py" in __init__
160. raise ValueError('badly formed hexadecimal UUID
string')
}}}

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

Django

unread,
Nov 12, 2018, 1:49:12 PM11/12/18
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned

Cleanup/optimization |
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* owner: nobody => Ian Foote
* status: new => assigned


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

Django

unread,
Nov 12, 2018, 2:24:54 PM11/12/18
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* has_patch: 0 => 1


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

Django

unread,
Feb 6, 2019, 3:57:26 AM2/6/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 0 => 1
* version: 2.1 => master


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

Django

unread,
Sep 17, 2019, 5:56:31 AM9/17/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:6>

Django

unread,
Sep 19, 2019, 7:51:48 AM9/19/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:7>

Django

unread,
Sep 23, 2019, 2:44:14 AM9/23/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d9881a025c15d87b2a7883ee50771117450ea90d" d9881a02]:
{{{
#!CommitTicketReference repository=""
revision="d9881a025c15d87b2a7883ee50771117450ea90d"
Fixed #29915 -- Added support for values with hyphens to pattern lookups
for UUIDField on backends without UUID datatype.

Support hyphens in iexact, contains, icontains, startswith, istartswith,
endswith and iendswith UUIDField filters on backends without UUID
datatype.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:10>

Django

unread,
Sep 23, 2019, 2:44:14 AM9/23/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"343afa788080fb874bcd10eab1a1a2fede98c526" 343afa7]:
{{{
#!CommitTicketReference repository=""
revision="343afa788080fb874bcd10eab1a1a2fede98c526"
Refs #29915 -- Doc'd limitation of using pattern lookups with UUIDField on
PostgreSQL.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:9>

Django

unread,
Sep 23, 2019, 2:44:14 AM9/23/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"485f65b3c010c25b8d75d1b40156db0fa9d5ca57" 485f65b]:
{{{
#!CommitTicketReference repository=""
revision="485f65b3c010c25b8d75d1b40156db0fa9d5ca57"
Refs #29915 -- Added tests for using pattern lookups with values without
hyphens for UUIDField.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:8>

Django

unread,
Sep 23, 2019, 2:45:10 AM9/23/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"368832e80308c15df7082ea4c42a2381529b4471" 368832e]:
{{{
#!CommitTicketReference repository=""
revision="368832e80308c15df7082ea4c42a2381529b4471"
[3.0.x] Refs #29915 -- Doc'd limitation of using pattern lookups with
UUIDField on PostgreSQL.

Backport of 343afa788080fb874bcd10eab1a1a2fede98c526 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:11>

Django

unread,
Sep 23, 2019, 2:48:07 AM9/23/19
to django-...@googlegroups.com
#29915: Allow icontains lookup to accept uuids with or without dashes
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: Ian Foote
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: uuid admin | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"ae2dee6ecf5090768c31be6695cc8a3a4201d177" ae2dee6e]:
{{{
#!CommitTicketReference repository=""
revision="ae2dee6ecf5090768c31be6695cc8a3a4201d177"
[2.2.x] Refs #29915 -- Doc'd limitation of using pattern lookups with
UUIDField on PostgreSQL.

Backport of 343afa788080fb874bcd10eab1a1a2fede98c526 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:12>

Reply all
Reply to author
Forward
0 new messages