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.
* 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>
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>
* owner: nobody => Ian Foote
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:3>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:4>
* needs_better_patch: 0 => 1
* version: 2.1 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29915#comment:7>
* 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>
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>
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>
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>
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>