Re: [Django] #33562: set_cookie and set_signed_cookie should accept timedelta object for max_age argument

32 views
Skip to first unread message

Django

unread,
Mar 5, 2022, 6:22:14 AM3/5/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------+--------------------------------------
Reporter: Luke Plant | Owner: Luke Plant
Type: New feature | Status: assigned
Component: HTTP handling | Version: 4.0
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
-------------------------------+--------------------------------------
Changes (by Luke Plant):

* owner: nobody => Luke Plant
* status: new => assigned


Comment:

PR here - https://github.com/django/django/pull/15481

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

Django

unread,
Mar 5, 2022, 6:22:15 AM3/5/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------+--------------------------------------
Reporter: Luke Plant | Owner: Luke Plant
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
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 Claude Paroz):

* has_patch: 0 => 1
* version: 4.0 => dev
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 5, 2022, 6:26:56 AM3/5/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-----------------------------------------+------------------------
Reporter: Luke Plant | Owner: nobody
Type: New feature | Status: new

Component: HTTP handling | Version: 4.0
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 |
-----------------------------------------+------------------------
This already works for `get_signed_cookie`:
{{{#!python
>>> request.get_signed_cookie("mykey", max_age=timedelta(days=3))
}}}

This is due to the underlying behaviour of `TimestampSigner`, which was
fixed to do this in #21363.

But for `set_cookie` and `set_signed_cookie` it accepts only a number:

{{{#!python
>>> response = HttpResponse()
>>> response.set_cookie("mykey", max_age=timedelta(days=3))
TypeError: int() argument must be a string, a bytes-like object or a
number, not 'datetime.timedelta'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33562>

Django

unread,
Mar 7, 2022, 2:05:47 AM3/7/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------------+-------------------------------------

Reporter: Luke Plant | Owner: Luke
| Plant
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
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):

* stage: Accepted => Ready for checkin


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

Django

unread,
Mar 7, 2022, 4:12:03 AM3/7/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------------+-------------------------------------
Reporter: Luke Plant | Owner: Luke
| Plant
Type: New feature | Status: closed

Component: HTTP handling | Version: dev
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:"ae2da5ba652c1a11cd88dcb119744dcecaeb03ee" ae2da5ba]:
{{{
#!CommitTicketReference repository=""
revision="ae2da5ba652c1a11cd88dcb119744dcecaeb03ee"
Fixed #33562 -- Made HttpResponse.set_cookie() support timedelta for the
max_age argument.
}}}

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

Django

unread,
Mar 7, 2022, 4:12:03 AM3/7/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------------+-------------------------------------
Reporter: Luke Plant | Owner: Luke
| Plant
Type: New feature | Status: closed
Component: HTTP handling | Version: dev
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:"f3bf6c4218404479f7841e0af213d5db65913278" f3bf6c42]:
{{{
#!CommitTicketReference repository=""
revision="f3bf6c4218404479f7841e0af213d5db65913278"
Refs #33562 -- Made HttpResponse.set_cookie() raise ValueError when both
"expires" and "max_age" are passed.

This fixes the case where you might pass set_cookie(expires=val,
max_age=val)
and max_age is silently ignored.
}}}

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

Django

unread,
Mar 7, 2022, 4:12:03 AM3/7/22
to django-...@googlegroups.com
#33562: set_cookie and set_signed_cookie should accept timedelta object for max_age
argument
-------------------------------------+-------------------------------------
Reporter: Luke Plant | Owner: Luke
| Plant
Type: New feature | Status: assigned

Component: HTTP handling | Version: dev
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
-------------------------------------+-------------------------------------

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

In [changeset:"1882f6567df361f52e53b555b2faa677361e128a" 1882f656]:
{{{
#!CommitTicketReference repository=""
revision="1882f6567df361f52e53b555b2faa677361e128a"
Refs #33562 -- Added tests HttpRequest.get_signed_cookie() with
timedeltas.
}}}

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

Reply all
Reply to author
Forward
0 new messages