[Django] #25571: When number argument is not an integer ungettext_lazy's return value evaluates to False

25 views
Skip to first unread message

Django

unread,
Oct 19, 2015, 12:43:42 PM10/19/15
to django-...@googlegroups.com
#25571: When number argument is not an integer ungettext_lazy's return value
evaluates to False
-----------------------------------+--------------------
Reporter: teddy_beer_maniac | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
When I tried to pass ungettext_lazy as the message argument for
MinLengthValidator:
{{{
MinLengthValidator(4, ungettext_lazy(
'Name has to be at least %(limit_value)d character long.',
'Name has to be at least %(limit_value)d characters long.',
'limit_value'
))
}}}
the default message was still used. After fiddling around I found out,
that it's because ungettext_lazy's return value's `__len__` returns 0
which makes it evaluate to False and fail a check in BaseValidator's
constructor.
{{{
>>> len(ungettext_lazy('%(number)d object', '%(number)d objects',
'number'))
0
>>> len(ungettext_lazy('%(number)d object', '%(number)d objects', 1))
17
>>> bool(ungettext_lazy('%(number)d object', '%(number)d objects',
'number'))
False
>>> bool(ungettext_lazy('%(number)d object', '%(number)d objects', 1))
True
}}}
I'm not sure if this behaviour is a bug, or is it by design and it's a bug
in BaseValidator's constructor, but I assume it's the former.

Using django 1.8.5, checked on python 2.7.9 and 3.4.3.

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

Django

unread,
Oct 19, 2015, 3:50:33 PM10/19/15
to django-...@googlegroups.com
#25571: When number argument is not an integer ungettext_lazy's return value
evaluates to False
--------------------------------------+------------------------------------

Reporter: teddy_beer_maniac | Owner: nobody
Type: Bug | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* component: Utilities => Internationalization
* needs_tests: => 0
* needs_docs: => 0
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Yes, that's a bug. Possible resolution:
[https://github.com/django/django/pull/5447 PR]

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

Django

unread,
Oct 20, 2015, 8:25:51 PM10/20/15
to django-...@googlegroups.com
#25571: When number argument is not an integer ungettext_lazy's return value
evaluates to False
-------------------------------------+-------------------------------------

Reporter: teddy_beer_maniac | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: | 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 timgraham):

* stage: Accepted => Ready for checkin


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

Django

unread,
Oct 22, 2015, 9:19:50 AM10/22/15
to django-...@googlegroups.com
#25571: When number argument is not an integer ungettext_lazy's return value
evaluates to False
-------------------------------------+-------------------------------------
Reporter: teddy_beer_maniac | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution: fixed

Keywords: | 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 Claude Paroz <claude@…>):

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


Comment:

In [changeset:"8b5acda8214c2b8fd73298e106d99627c5815d97" 8b5acda]:
{{{
#!CommitTicketReference repository=""
revision="8b5acda8214c2b8fd73298e106d99627c5815d97"
Fixed #25571 -- Fixed boolean evaluation of ungettext_lazy
}}}

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

Reply all
Reply to author
Forward
0 new messages