[Django] #33935: Support unaccent function in JSONField values

31 views
Skip to first unread message

Django

unread,
Aug 17, 2022, 10:21:28 AM8/17/22
to django-...@googlegroups.com
#33935: Support unaccent function in JSONField values
-------------------------------------+-------------------------------------
Reporter: Foucauld | Owner: nobody
Degeorges |
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords: QuerySet.extra
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
With a JSONField value with the following shape: {{{
my_object.my_json_field = {"en": "sôme téxt"} }}}

Doing the following queryset:
{{{MyModel.objects.filter(my_json_field__en__unaccent__icontains="text")}}}
does not match the above record, because Django interprets "unaccent"' as
a key to find in the JSON dict, whereas I meant the PostgreSQL
{{{unaccent}}} function.

It seems that {{{ unaccent}}} is only supported on CharField and TextField
for now, but since what I am trying to do is possible in SQL, it might be
made possible as well using the ORM.

Details in this StackOverflow question:
https://stackoverflow.com/questions/73385812/looking-up-value-in-
jsonfield-with-unaccent-and-icontains
.

I am tagging QuerySet.extra because my workaround was to write the SQL
where clause I expected using {{{QuerySet.extra}}}.

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

Django

unread,
Aug 17, 2022, 10:44:08 AM8/17/22
to django-...@googlegroups.com
#33935: Support unaccent function in JSONField values
-------------------------------------+-------------------------------------
Reporter: Foucauld Degeorges | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Foucauld Degeorges:

Old description:

> With a JSONField value with the following shape: {{{
> my_object.my_json_field = {"en": "sôme téxt"} }}}
>
> Doing the following queryset:
> {{{MyModel.objects.filter(my_json_field__en__unaccent__icontains="text")}}}
> does not match the above record, because Django interprets "unaccent"' as
> a key to find in the JSON dict, whereas I meant the PostgreSQL
> {{{unaccent}}} function.
>
> It seems that {{{ unaccent}}} is only supported on CharField and
> TextField for now, but since what I am trying to do is possible in SQL,
> it might be made possible as well using the ORM.
>
> Details in this StackOverflow question:
> https://stackoverflow.com/questions/73385812/looking-up-value-in-
> jsonfield-with-unaccent-and-icontains
> .
>
> I am tagging QuerySet.extra because my workaround was to write the SQL
> where clause I expected using {{{QuerySet.extra}}}.

New description:

With a JSONField value with the following shape: {{{
my_object.my_json_field = {"en": "sôme téxt"} }}}

Doing the following queryset:
{{{MyModel.objects.filter(my_json_field__en__unaccent__icontains="text")}}}
does not match the above record, because Django interprets "unaccent"' as
a key to find in the JSON dict, whereas I meant the PostgreSQL
{{{unaccent}}} function.

By comparison, with a CharField,
{{{MyModel.objects.filter(my_char_field__unaccent__icontains="test")}}}
works as expected.

It seems that {{{ unaccent}}} is only supported on CharField and TextField
for now, but since what I am trying to do is possible in SQL, it might be
made possible as well using the ORM.

Details in this StackOverflow question:
https://stackoverflow.com/questions/73385812/looking-up-value-in-
jsonfield-with-unaccent-and-icontains
.

I am tagging QuerySet.extra because my workaround was to write the SQL
where clause I expected using {{{QuerySet.extra}}}.

--

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

Django

unread,
Aug 17, 2022, 11:14:42 AM8/17/22
to django-...@googlegroups.com
#33935: Support unaccent function in JSONField values
-------------------------------------+-------------------------------------
Reporter: Foucauld Degeorges | Owner: nobody
Type: Uncategorized | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

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


Comment:

Duplicate of #26511 (see also #27824 and
[https://code.djangoproject.com/ticket/27824#comment:8 Simon's comment]).

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

Reply all
Reply to author
Forward
0 new messages