In order to check the existence of a key in a TodoistAPI
class I use the "in" keyword. However, it causes a KeyError
.
I isolated the code fragments to check what exactly causes the KeyError
and which inputs are provided.
api = TodoistAPI(token)
api.sync()
print("id" in api.state["items"][0])
api.state["items"][0]
contains:
Item({'assigned_by_uid': None,
'checked': 0,
'child_order': 0,
'collapsed': 0,
'content': 'example task',
'date_added': '0',
'date_completed': None,
'day_order': 0,
'due': {'date': '0',
'is_recurring': True,
'lang': 'de',
'string': 'every day',
'timezone': None},
'has_more_notes': False,
'id': 0,
'in_history': 0,
'is_deleted': 0,
'labels': [0, 0],
'parent_id': None,
'priority': 1,
'project_id': 0,
'responsible_uid': None,
'section_id': None,
'sync_id': None,
'user_id': 0})
I expect the output of print(...)
to be True
or False
, but the actual output is as follows
Traceback (most recent call last):
File "/Users/path/to/file.py", line 11, in
print("id" in applicationInterface.state["items"][0])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/todoist/models.py", line 16, in __getitem__
return self.data[key]
KeyError: 0
Process finished with exit code 1
I also created an issue in the Todoist Github-Repository: https://github.com/Doist/todoist-python/issues/64