Move GcmPushkin aiohttp.ClientSession to async create() factory#431
Open
wcjord wants to merge 1 commit intoelement-hq:mainfrom
Open
Move GcmPushkin aiohttp.ClientSession to async create() factory#431wcjord wants to merge 1 commit intoelement-hq:mainfrom
wcjord wants to merge 1 commit intoelement-hq:mainfrom
Conversation
aiohttp.ClientSession should be instantiated within a running async event loop, but GcmPushkin was creating it in __init__ (synchronous). This causes deprecation warnings in newer aiohttp versions and can fail in contexts where no event loop is running. Override the base Pushkin.create() classmethod to move the ClientSession and google_auth_request initialization to async context. Signed-off-by: William Jordan-Cooley <william@pangea.chat> Signed-off-by: wcjord <32568597+wcjord@users.noreply.github.com>
4 tasks
| @@ -0,0 +1 @@ | |||
| Move aiohttp.ClientSession creation to async create() factory to avoid deprecation warning when instantiated outside a running event loop. | |||
Member
There was a problem hiding this comment.
Suggested change
| Move aiohttp.ClientSession creation to async create() factory to avoid deprecation warning when instantiated outside a running event loop. | |
| Move `aiohttp.ClientSession` creation to async `create()` factory to avoid deprecation warning when instantiated outside a running event loop. |
There was a problem hiding this comment.
Pull request overview
This PR moves aiohttp.ClientSession creation for GcmPushkin out of __init__ and into an async factory method to ensure it is instantiated within a running event loop (avoiding warnings/failures with newer aiohttp).
Changes:
- Add
GcmPushkin.create()async factory and movegoogle_auth_requestinitialization there. - Update
GcmPushkin.__init__to defergoogle_auth_requestinitialization. - Add a changelog fragment documenting the bugfix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sygnal/gcmpushkin.py |
Introduces an async create() factory to initialize aiohttp/google-auth components inside an event loop. |
changelog.d/gcm-async-create.bugfix |
Records the change as a bugfix in the changelog system. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+224
to
+229
| """ | ||
| Async factory that creates a GcmPushkin instance. | ||
|
|
||
| aiohttp.ClientSession must be created within a running event loop, | ||
| so we override create() to handle that initialization. | ||
| """ |
| @@ -0,0 +1 @@ | |||
| Move aiohttp.ClientSession creation to async create() factory to avoid deprecation warning when instantiated outside a running event loop. | |||
Member
There was a problem hiding this comment.
Note that changelog entries should be named using the PR #. So this file should be renamed to: 431.bugfix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
aiohttp.ClientSessionshould be instantiated within a running async event loop, butGcmPushkinwas creating it in__init__(synchronous). This causes deprecation warnings in newer aiohttp versions and can fail in contexts where no event loop is running.Changes
Pushkin.create()classmethod inGcmPushkinto moveClientSessionandgoogle_auth_requestinitialization to async contextChangelog
changelog.d/gcm-async-create.bugfixincluded.Signed-off-by: wcjord 32568597+wcjord@users.noreply.github.com