Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dict of a Document instance leads to TypeError #231

Open
larsborn opened this issue Aug 13, 2022 · 0 comments
Open

dict of a Document instance leads to TypeError #231

larsborn opened this issue Aug 13, 2022 · 0 comments

Comments

@larsborn
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant