Skip to content

dict of a Document instance leads to TypeError #231

@larsborn

Description

@larsborn

I expected that the following code will print all key/value pairs from the document with key existing_document_key:

doc = connection['your_database']['your_collection']['existing_document_key']
for key, value in dict(doc).items():
    print(f'{key}: {value}')

But it causes a TypeError: 'NoneType' object is not callable exception in the for key, value in dict(doc).items(): line. After some digging, it looks as if the __dict__ implementation of the pyArango.document.Document class is not correct:

def __dict__(self):
    if not self._store:
        return {}
    return dict(self._store)

But DocumentStore does not implement any sensible __dict__ method. Might it be that the __dict__ method of Document` should rather be:

def __dict__(self):
    if not self._store:
        return {}
    return self._store.getStore()

P.S.: After writing up this issue, I was also able to rewrite my initial code to

doc = connection['your_database']['your_collection']['existing_document_key']
for key, value in doc.getStore().items():
    print(f'{key}: {value}')

I would be happy create an MR for the behavior change of __dict__ in Document or, alternatively, to add a paragraph to the README.md or documentation. If there is an even better solution, I'd also be happy to contribute. Just let me know what you prefer!

Environment:

  • Python Version: 3.9
  • Operating System: Windows
  • pyArango Version: 2.,0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions