Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-480

Sub-collection issue when using ABCMeta

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.0
    • None
    • None
    • Not environment dependent
    • Minor Change

    Description

      I hit an issue recently when using pymongo inside Abstract Base Class. For example the test.py file raise an exception when executed:

      Traceback (most recent call last):
        File "test.py", line 8, in <module>
          a = A()
      TypeError: Can't instantiate abstract class A with abstract methods col

      It's because ABCMeta try to get attribute __isabstractmethod__ on Collection (https://github.com/python-git/python/blob/master/Lib/abc.py#L80) and Collection return a sub-collection in __getattr__ (https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py#L130).

      A simple fix could be to not return a sub-collection if name begins with "__".

      I can write a workaround for this issue but adding "col.__isabstractmethod__ = False" is not very clean.

      I hope the issue is clear enough.

      Attachments

        1. longer_example.py
          1 kB
        2. test.py
          0.1 kB

        Issue Links

          Activity

            People

              bernie@mongodb.com Bernie Hackett
              lothiraldan FELD Boris
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: