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

Sub-collection issue when using ABCMeta

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      Not environment dependent
    • Minor Change

      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.

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

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

              Created:
              Updated:
              Resolved: