Fair enough.
(Side note: It’s usually more helpful to post the traceback from the server console than the error page from the browser, but I think this is good enough for now.)
Looking at the Django docs for set_expiry in version 4.0:
Note that
datetimeandtimedeltavalues are only serializable if you are using thePickleSerializer.
This means that to use this parameter with this version of Django, you need to change your serializer for the sessions. (According to the docs, directly saving a datetime value in the session using the JSON serializer became available in 4.1.)
Another side note, I guess my first question is when are you trying to set this? If you’re setting this in every view, or in multiple views, or in custom middleware, then it’s going to be recalculated and updated on each request.