aio-libs / aiopg

aiopg is a library for accessing a PostgreSQL database from the asyncio
http://aiopg.readthedocs.io
BSD 2-Clause "Simplified" License
1.4k stars 160 forks source link

NotImplementedError 😢 #905

Closed daeeros closed 10 months ago

daeeros commented 10 months ago

Describe the bug

NotImplementedError raises

I try to fix it like asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) but not helped.

To Reproduce

  1. pip install peewee_async aiopg
  2. run this code
import peewee
import peewee_async
import asyncio

database = peewee_async.PostgresqlDatabase(database="test", host="localhost", user="postgres", password="test123123")

class BaseModel(peewee.Model):
    class Meta:
        database = database

class User(BaseModel):
    user_id = peewee.BigIntegerField(primary_key=True, unique=True)

    class Meta:
        indexes = (
            (('user_id',), True),
        )

database.create_tables((User,), safe=True)
database.set_allow_sync(False)
manager = peewee_async.Manager(database)

async def test():
    await manager.create(User, user_id=1)
    print("ok!")

asyncio.run(test())

Expected behavior

Connection opened and executed normaly.

Logs/tracebacks

Future exception was never retrieved
future: <Future finished exception=NotImplementedError()>
Traceback (most recent call last):
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 740, in connect_async
    await conn.connect()
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 901, in connect
    self.pool = await aiopg.create_pool(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\pool.py", line 300, in from_pool_fill
    await self._fill_free_pool(False)
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\pool.py", line 336, in _fill_free_pool
    conn = await connect(
                 ^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\connection.py", line 65, in connect
    connection = Connection(
                 ^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\connection.py", line 772, in __init__
    self._loop.add_reader(
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\asyncio\events.py", line 534, in add_reader
    raise NotImplementedError
NotImplementedError
kutana.py      [L:179 ]ERROR  [23:04:32] Exception while handling the update
Traceback (most recent call last):
  File "C:\Users\root\Desktop\Celestiana\kutana\kutana.py", line 175, in _handle_update_with_logger
    return await self._handle_update(update, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\kutana\kutana.py", line 201, in _handle_update
    if await router.handle(update, ctx) != hr.SKIPPED:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\kutana\router.py", line 116, in handle
    processed = await handler.handle(update, ctx)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\plugins\test.py", line 7, in _
    user = await manager.create(User, user_id=1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 186, in create
    pk = await self.execute(query)
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 272, in execute
    return (await execute(query))
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 432, in execute
    return (await coroutine(query))
            ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 466, in insert
    cursor = await _execute_query_async(query)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 1317, in _execute_query_async
    return (await _run_sql(database, *query.sql()))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 1297, in _run_sql
    cursor = await database.cursor_async()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 754, in cursor_async
    await self.connect_async(loop=self._loop)
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 740, in connect_async
    await conn.connect()
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\peewee_async.py", line 901, in connect
    self.pool = await aiopg.create_pool(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\pool.py", line 300, in from_pool_fill
    await self._fill_free_pool(False)
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\pool.py", line 336, in _fill_free_pool
    conn = await connect(
                 ^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\connection.py", line 65, in connect
    connection = Connection(
                 ^^^^^^^^^^^
  File "C:\Users\root\Desktop\Celestiana\env\Lib\site-packages\aiopg\connection.py", line 772, in __init__
    self._loop.add_reader(
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\asyncio\events.py", line 534, in add_reader
    raise NotImplementedError
NotImplementedError

Python Version

$ python --version
Python 3.12.1

aiopg Version

$ python -m pip show aiopg
Name: aiopg
Version: 1.4.0
Summary: Postgres integration with asyncio.
Home-page: https://aiopg.readthedocs.io
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: BSD
Location: C:\Users\root\Desktop\Celestiana\env\Lib\site-packages
Requires: async-timeout, psycopg2-binary
Required-by:

OS

Windows 10 Home 22H2 X64

Additional context

No response

Code of Conduct