-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
As reported in https://github.com/mongodb/motor/pull/59 motor's Database and Collection classes cannot be subclassed. The following should work:
@asyncio_test async def test_database_subclass(self): class MyDB(AsyncIOMotorDatabase): async def ping(self): return await self.command('ping') db = MyDB(self.cx, 'motor_test') res = await db.ping() self.assertTrue(res['ok'])
Instead it raises this error:
ERROR: test_database_subclass (test.asyncio_tests.test_asyncio_database.TestAsyncIODatabase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/shane/git/motor/test/asyncio_tests/__init__.py", line 48, in __call__ result = self.orig_method() File "/Users/shane/git/motor/test/asyncio_tests/__init__.py", line 213, in wrapped self.loop.run_until_complete(task) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/Users/shane/git/motor/test/asyncio_tests/test_asyncio_database.py", line 50, in test_database_subclass db = MyDB(self.cx, 'motor_test') File "/Users/shane/git/motor/motor/core.py", line 519, in __init__ super(self.__class__, self).__init__(delegate) TypeError: __init__() missing 1 required positional argument: 'name'