Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33562 closed New feature (fixed)

set_cookie and set_signed_cookie should accept timedelta object for max_age argument

Reported by: Luke Plant Owned by: Luke Plant
Component: HTTP handling Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This already works for get_signed_cookie:

>>> 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:

>>> 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'

Change History (6)

comment:1 by Luke Plant, 3 years ago

Owner: changed from nobody to Luke Plant
Status: newassigned

comment:2 by Claude Paroz, 3 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Version: 4.0dev

comment:3 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 1882f656:

Refs #33562 -- Added tests HttpRequest.get_signed_cookie() with timedeltas.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In ae2da5ba:

Fixed #33562 -- Made HttpResponse.set_cookie() support timedelta for the max_age argument.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In f3bf6c42:

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.

Note: See TracTickets for help on using tickets.
Back to Top