Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix get_session_remaining_seconds() for rolling sessions #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deepcyrille
Copy link

get_session_remaining_seconds() should return last_update + lifetime - now instead of created + lifetime - now.

@deepcyrille deepcyrille force-pushed the fix_rolling_sessions_remaining_seconds branch 2 times, most recently from 65b13d1 to 1b5f783 Compare March 27, 2024 07:58
`get_session_remaining_seconds()` should return `last_update + lifetime - now` instead of `created + lifetime - now`.

Fix mypy: use FixtureRequest instead of SubRequest

`SubRequest` is a subclass of `FixtureRequest`, but is currently private
so pytest-asyncio uses `Any` instead. However, `FixtureRequest` typing
is sufficient for our needs, so can use that instead.
@deepcyrille deepcyrille force-pushed the fix_rolling_sessions_remaining_seconds branch from 1b5f783 to 0ff538a Compare March 27, 2024 07:58
return int((metadata["created"] + metadata["lifetime"]) - now)
# use "last_update" if rolling session, otherwise use "created"
rolling = metadata.get("rolling", False)
last_update = metadata["last_update"] if rolling and "last_update" in metadata else metadata["created"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we will use last_access everywhere? This seems very natural to me. Rolling session is alive while it's being used. So last_access may work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but last_access is updated before in the load function, whereas last_update is updated in the save function

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should use last_access here, as the purpose of rolling session is not to expire while being used.
last_access is the timestamp when the session was last loaded, read used.

I think that we should not use last_updated to count session remaining time because I think it is a good idea not to call handler.save at all if session was not modified to avoid network round trip, e.g. with Redis backend (feature out of scope).

Since we always update last_access on every load (read endpoint call), we do extend rolling session TTL by this action. So, my opinion is just to use last_access in place of created and this should solve your requirement.

@deepcyrille
Copy link
Author

Anything I should do to get this PR released?

@alex-oleshkevich
Copy link
Owner

I will get back to it in 2-3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants