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

coroutine 'Connection.disconnect' was never awaited #1462

Open
1 task done
IOANNB4R opened this issue Dec 24, 2022 · 0 comments
Open
1 task done

coroutine 'Connection.disconnect' was never awaited #1462

IOANNB4R opened this issue Dec 24, 2022 · 0 comments
Labels

Comments

@IOANNB4R
Copy link

IOANNB4R commented Dec 24, 2022

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
@IOANNB4R IOANNB4R added the bug label Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant