Skip to content

Move GcmPushkin aiohttp.ClientSession to async create() factory#431

Open
wcjord wants to merge 1 commit intoelement-hq:mainfrom
pangeachat:fix/gcm-async-create
Open

Move GcmPushkin aiohttp.ClientSession to async create() factory#431
wcjord wants to merge 1 commit intoelement-hq:mainfrom
pangeachat:fix/gcm-async-create

Conversation

@wcjord
Copy link
Copy Markdown

@wcjord wcjord commented Mar 2, 2026

Summary

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.

Changes

  • Override the base Pushkin.create() classmethod in GcmPushkin to move ClientSession and google_auth_request initialization to async context
  • Add unit tests verifying the async factory path

Changelog

changelog.d/gcm-async-create.bugfix included.

Signed-off-by: wcjord 32568597+wcjord@users.noreply.github.com

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>
@wcjord wcjord requested a review from a team as a code owner March 2, 2026 19:01
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

@wcjord wcjord mentioned this pull request Mar 2, 2026
4 tasks
Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

The code LGTM, thank you for upstreaming your work!

Add unit tests verifying the async factory path

Do you mean to include these tests in your PR?

@@ -0,0 +1 @@
Move aiohttp.ClientSession creation to async create() factory to avoid deprecation warning when instantiated outside a running event loop.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 move google_auth_request initialization there.
  • Update GcmPushkin.__init__ to defer google_auth_request initialization.
  • 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that changelog entries should be named using the PR #. So this file should be renamed to: 431.bugfix

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.

4 participants