Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-614

Database and Collection classes cannot be subclassed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Component/s: None
    • Labels:

      Description

      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'
      

        Attachments

          Activity

            People

            Assignee:
            prashant.mital Prashant Mital (Inactive)
            Reporter:
            shane.harvey Shane Harvey
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: