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

Use the async session.asave method if it exists #2092

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

bigfootjon
Copy link
Collaborator

Support was added in django/django#17372 (slated for release in 5.1)

We can use this API if it exists, otherwise, we fallback to a sync_to_async bridge.

This does break backwards compatibility, which I'm not terribly happy about but I'm not sure how best to fix it.

If users overrode save_session in a subclass they would expect that to still work, so I thought the best way to do this was to make it async in the base class and then await it, so at least it will be obvious that it doesn't work (python will raise an exception about awaiting a non-awaitable), but I'm open to other solutions.

channels/sessions.py Outdated Show resolved Hide resolved
@bigfootjon
Copy link
Collaborator Author

@carltongibson: I've added the missing test coverage (such as I could, see inline comment) and fixed the thing you noted.

I'm not sure this should be merged before #2090 is resolved since sessions can use the Django ORM under the hood.

@carltongibson
Copy link
Member

Yes, I too was thinking we need to settle that first 👍

@carltongibson
Copy link
Member

Ref the breaking change here: I think if we're super clear in the release notes that may have to do.

@bigfootjon
Copy link
Collaborator Author

Alright, we've got full test coverage now!

@bigfootjon
Copy link
Collaborator Author

Once this PR is merged I'll add the backwards compat notices to: #2111

Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

OK, bar the one comment (which. I think is messaging rather than a blocker) This looks good. 👍

@bigfootjon bigfootjon merged commit e39fe13 into django:main Jul 30, 2024
6 checks passed
@bigfootjon bigfootjon deleted the async-sessions-api branch July 30, 2024 00:49
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