From d61785b2e8d18438e5031de9c49e61642e5cfb3f Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 4 Nov 2025 10:03:39 +0000 Subject: [PATCH] Ignore `expires` and `max_age` arguments if passed to `Response.delete_cookie` (Fixes #323) --- src/microdot/microdot.py | 8 ++++++-- src/microdot/session.py | 5 ++++- tests/test_microdot.py | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/microdot/microdot.py b/src/microdot/microdot.py index 1b78b61..5a4f8c2 100644 --- a/src/microdot/microdot.py +++ b/src/microdot/microdot.py @@ -632,9 +632,13 @@ class Response: """Delete a cookie. :param cookie: The cookie's name. - :param kwargs: Any cookie opens and flags supported by - ``set_cookie()`` except ``expires`` and ``max_age``. + :param kwargs: Any cookie options and flags supported by + :meth:`set_cookie() `. + Values given for ``expires`` and ``max_age`` are + ignored. """ + kwargs.pop('expires', None) + kwargs.pop('max_age', None) self.set_cookie(cookie, '', expires='Thu, 01 Jan 1970 00:00:01 GMT', max_age=0, **kwargs) diff --git a/src/microdot/session.py b/src/microdot/session.py index d8ce085..cbfb0a8 100644 --- a/src/microdot/session.py +++ b/src/microdot/session.py @@ -25,7 +25,10 @@ class SessionDict(dict): class Session: """ :param app: The application instance. - :param key: The secret key, as a string or bytes object. + :param secret_key: The secret key, as a string or bytes object. + :param cookie_options: A dictionary with cookie options to pass as + arguments to :meth:`Response.set_cookie() + `. """ secret_key = None diff --git a/tests/test_microdot.py b/tests/test_microdot.py index 71e0d26..3f66fca 100644 --- a/tests/test_microdot.py +++ b/tests/test_microdot.py @@ -204,9 +204,10 @@ class TestMicrodot(unittest.TestCase): res.set_cookie('four', '4') res.delete_cookie('two', path='/') res.delete_cookie('one', path='/bad') + res.delete_cookie('five', max_age=123, expires='foo') return res - client = TestClient(app, cookies={'one': '1', 'two': '2'}) + client = TestClient(app, cookies={'one': '1', 'two': '2', 'five': '5'}) res = self._run(client.get('/', headers={'Cookie': 'three=3'})) self.assertEqual(res.status_code, 200) self.assertEqual(res.headers['Content-Type'],