Skip to content

Getting "RuntimeError: GitHub client has already been collected." error while using API from a Task #109

@FeodorFitsner

Description

@FeodorFitsner

I have the following module:

import logging

from githubkit import AppAuthStrategy, AppInstallationAuthStrategy, GitHub
from githubkit.exception import RequestFailed

from textmd import config

logger = logging.getLogger("pull_request_opened")


def installation_github(installation_id: int):
    return GitHub(
        AppInstallationAuthStrategy(
            config.GitHubAppID,
            config.GithubAppPrivateKey.replace("\\n", "\n"),
            installation_id,
        )
    )


async def pull_request_opened(
    installation_id: int,
    owner: str,
    repo: str,
    pull_request_id: int,
    settings: dict[str, str],
):
    logger.info(
        f"Start: installation_id={installation_id}, pull_request_id={pull_request_id}"
    )

    pr = (
        await installation_github(installation_id).rest.pulls.async_get(
            owner, repo, pull_request_id
        )
    ).parsed_data

    logger.info(f"Pull request title: {pr.title}")

While trying to call pull_request_opened() in a Task:

asyncio.create_task(
            pull_request_opened(
                event.installation.id,
                event.repository.owner.login,
                event.repository.name,
                event.pull_request.id,
                {},
            )

I'm getting error:

RuntimeError: GitHub client has already been collected. Do not use the namespace after the client has been collected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions