Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

coroutine 'Connection.disconnect' was never awaited #1462

@IOANNB4R

Description

@IOANNB4R

Describe the bug

Hello. I always get the runtime warning when I stop my code. The on_startup function is called when the aiogram application starts

To Reproduce

Run the following code

from aioredis import Redis
from aiogram import Dispatcher

from typing import Dict


class Params:

  def __init__(self) -> None:
    self.redis = None

  async def get_redis(self) -> Redis:
    if not self.redis:
      self.redis = Redis(host='redis', password='redis_password')

    return self.redis

  async def get_params(self) -> Dict:
    redis = await self.get_redis()
    return await redis.get('PARAMS')

  async def close(self) -> None:
    if self.redis:
      await self.redis.close()

params = Params()


async def on_startup(dispatcher: Dispatcher) -> None:
  print(await params.get_params())
  await params.close()

Stop the code

Expected behavior

No runtime warning when the code stops because I manually close the redis connection

Logs/tracebacks

sys:1: RuntimeWarning: coroutine 'Connection.disconnect' was never awaited

Python Version

Python 3.10.8

aioredis Version

Version: 2.0.1

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions