aio-libs-abandoned / aioredis-py

asyncio (PEP 3156) Redis support
https://aioredis.readthedocs.io/
MIT License
2.3k stars 336 forks source link

coroutine 'Connection.disconnect' was never awaited #1462

Open IOANNB4R opened 1 year ago

IOANNB4R commented 1 year ago

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