[Django] #34445: DateField.input_formats cannot be printed

1 view
Skip to first unread message

Django

unread,
Mar 29, 2023, 2:58:47 AM3/29/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-----------------------------------------+------------------------
Reporter: stefan6419846 | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I am trying to display the input formats for
`django.forms.fields.DateField`. This seems to fail at the moment when
using `__str__`, while `__repr__` works.

Example code:

{{{
from django.forms.fields import DateField


print(repr(DateField().input_formats))
print(DateField().input_formats)
}}}

This will result in the following error:

{{{
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: __str__ returned non-string (type list)
}}}

I would have expected the string representation to be available as well
instead of failing with an internal Python error.

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

Django

unread,
Mar 29, 2023, 5:47:44 AM3/29/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------+--------------------------------------

Reporter: stefan6419846 | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
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 David Sanders):

Hi, thanks for the report!

Interesting:
{{{
> lazy_val = lazy(get_format, str, list, tuple)("DATE_INPUT_FORMATS")
> lazy_val.__str__()
['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y',
'%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y']
> str(lazy_val)
*** TypeError: __str__ returned non-string (type list)
}}}

The `__str__()` on the proxy object doesn't seem to be called when
evaluated through `str()` 🤔

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

Django

unread,
Mar 29, 2023, 5:59:44 AM3/29/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------+------------------------------------
Reporter: stefan6419846 | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* type: Uncategorized => Bug
* component: Uncategorized => Utilities
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 29, 2023, 6:08:29 AM3/29/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------+-----------------------------------------
Reporter: stefan6419846 | Owner: David Sanders
Type: Bug | Status: assigned

Component: Utilities | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Changes (by David Sanders):

* owner: nobody => David Sanders
* status: new => assigned


Comment:

PR: https://github.com/django/django/pull/16701

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

Django

unread,
Mar 30, 2023, 5:45:27 AM3/30/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------------+-------------------------------------

Reporter: stefan6419846 | Owner: David
| Sanders
Type: Bug | Status: assigned
Component: Utilities | Version: 3.2
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 Mariusz Felisiak):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/16707 Alternative PR].

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

Django

unread,
Mar 30, 2023, 6:51:51 AM3/30/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------------+-------------------------------------
Reporter: stefan6419846 | Owner: David
| Sanders
Type: Bug | Status: closed
Component: Utilities | Version: 3.2
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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"066aabcb77579cf8d549119c860d11cd15e3eef1" 066aabc]:
{{{
#!CommitTicketReference repository=""
revision="066aabcb77579cf8d549119c860d11cd15e3eef1"
Fixed #34445 -- Fixed string-casting of non-string lazy objects.

This removes __text_cast() as it's the same as __cast().
_delegate_bytes and __delegate_text are mutually exclusive so the
`if self._delegate_bytes` branch in __cast() is unreachable.

Co-Authored-By: David Sanders <shang.xia...@gmail.com>
}}}

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

Django

unread,
Jun 8, 2023, 1:36:09 AM6/8/23
to django-...@googlegroups.com
#34445: DateField.input_formats cannot be printed
-------------------------------------+-------------------------------------
Reporter: stefan6419846 | Owner: David
| Sanders
Type: Bug | Status: closed
Component: Utilities | Version: 3.2
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
-------------------------------------+-------------------------------------

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

In [changeset:"f5817c24f44aa90188757ddca1e5e63ba6f5df75" f5817c2]:
{{{
#!CommitTicketReference repository=""
revision="f5817c24f44aa90188757ddca1e5e63ba6f5df75"
Refs #34445 -- Fixed string-casting of non-string lazy objects when value
may be bytes.

If the result type is bytes, then calling bytes() on it does nothing.

If the result type is not bytes, we should not cast to bytes, just
because the return value may be bytes.
}}}

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

Reply all
Reply to author
Forward
0 new messages