[Django] #30435: __icontains NOT WORKING. URGENT!!!!!!!!!!!!!!!!!!!!!!!

5 views
Skip to first unread message

Django

unread,
May 2, 2019, 7:10:50 PM5/2/19
to django-...@googlegroups.com
#30435: __icontains NOT WORKING. URGENT!!!!!!!!!!!!!!!!!!!!!!!
-------------------------------------+-------------------------------------
Reporter: Diego | Owner: nobody
Arturo Hernandez Fuentes |
Type: Bug | Status: new
Component: | Version: 2.1
Uncategorized |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have my query into validation to find if exist a duplicate name in my
model


{{{
def validate_name(self, value):
if not value:
raise serializers.ValidationError('Proporciona un valor, por
favor.')

try:
exist_name = FundingSource.objects.filter(name__iexact=value)
# here is the error __icontains is NOT WORKING
if len(exist_name) > 0:
raise serializers.ValidationError('Este nombre ya fue
usado, por favor proporciona otro valor.') # I need display this message
in my console to be sure that exists a duplicate
except Exception as e:
pass
else:
return value
}}}

I have in my model

Funding 1
Funding 2
Funding 3
Funding 4

Next, I tried to type `funding 1` to disallow me to create that name, but,
the queryset display me

<QuerySet []>

Then, create new one item in my table.

Funding 1
Funding 2
Funding 3
Funding 4
funding 1

So this is wrong, your __iexact is bad,

so I need that Django developer team resolve this, now.

It's urgent, please. What is the best way to develop __iexact or
__icontains.

Thanks


My django version is 2.1.5
Django rest framework version = 3.9.0

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

Django

unread,
May 2, 2019, 7:11:07 PM5/2/19
to django-...@googlegroups.com
#30435: __iexactNOT WORKING. URGENT!!!!!!!!!!!!!!!!!!!!!!!
-------------------------------------+-------------------------------------
Reporter: Diego Arturo | Owner: nobody

Hernandez Fuentes |
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
May 2, 2019, 7:11:27 PM5/2/19
to django-...@googlegroups.com
#30435: __iexact NOT WORKING. URGENT!!!!!!!!!!!!!!!!!!!!!!!
-------------------------------------+-------------------------------------
Reporter: Diego Arturo | Owner: nobody

Hernandez Fuentes |
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
May 2, 2019, 10:29:32 PM5/2/19
to django-...@googlegroups.com
#30435: __iexact NOT WORKING. URGENT!!!!!!!!!!!!!!!!!!!!!!!
-------------------------------------+-------------------------------------
Reporter: Diego Arturo | Owner: nobody

Hernandez Fuentes |
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Ryan Govostes):

You are raising your ValidationError inside a `try ... catch` block which
catches the exception and then does nothing with it. This will prevent the
ValidationError from escaping your validator.

Does this work?

{{{
def validate_name(self, value):
if not value:
raise serializers.ValidationError('Proporciona un valor, por
favor.')

exist_name = FundingSource.objects.filter(name__iexact=value)


if len(exist_name) > 0:
raise serializers.ValidationError('Este nombre ya fue usado,
por favor proporciona otro valor.')
}}}

Please keep bug report titles simple.

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

Django

unread,
May 2, 2019, 10:30:02 PM5/2/19
to django-...@googlegroups.com
#30435: __iexact not working inside validator function

-------------------------------------+-------------------------------------
Reporter: Diego Arturo | Owner: nobody
Hernandez Fuentes |
Type: Bug | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

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

Django

unread,
May 3, 2019, 1:04:06 AM5/3/19
to django-...@googlegroups.com
#30435: __iexact not working inside validator function.

-------------------------------------+-------------------------------------
Reporter: Diego Arturo | Owner: nobody
Hernandez Fuentes |
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => worksforme
* version: 2.1 => master
* component: Uncategorized => Database layer (models, ORM)


Comment:

First of all please don't shout. Secondly `__iexact` works properly, an
issue is in your own code. Tip from Ryan Govostes looks reasonable, but
your code will not work properly on update. You should take into account
instance etc. Nevertheless it is support issue so please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels].

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

Reply all
Reply to author
Forward
0 new messages