Doist / todoist-python

DEPRECATED The official Todoist Python API library
MIT License
535 stars 73 forks source link

api.sync() silently fails if no token set. #95

Open ijoseph opened 3 years ago

ijoseph commented 3 years ago

Expected behavior

 python -c "from todoist import TodoistAPI; api = TodoistAPI(); api.sync()"

outputs a warning indicating no token has been set.

Actual behavior

Fails silently; api.state is empty.

ijoseph commented 3 years ago

I fixed this but don't have perms to open a PR.

diff --git a/setup.py b/setup.py
index b6ec2aa..477d704 100644
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@ def read(fname):

 setup(
     name="todoist-python",
-    version="8.1.3",
+    version="8.1.4",
     packages=["todoist", "todoist.managers"],
     author="Doist Team",
     author_email="integrations@todoist.com",
diff --git a/todoist/api.py b/todoist/api.py
index 089f6dd..bdf42d1 100644
--- a/todoist/api.py
+++ b/todoist/api.py
@@ -347,6 +347,10 @@ class TodoistAPI(object):
         Sends to the server the changes that were made locally, and also
         fetches the latest updated data from the server.
         """
+
+        if not len(self.sync_token) or self.sync_token == '*':
+            print("Warning: token does not appear to be set; is {!r}".format(self.sync_token))
+
         post_data = {
             "token": self.token,
             "sync_token": self.sync_token,
ijoseph commented 3 years ago

Behavior after patch:

❯ python -c "from todoist import TodoistAPI; api = TodoistAPI(); api.sync()"
Warning: token does not appear to be set; is '*' 
PotHix commented 3 years ago

I fixed this but don't have perms to open a PR.

You can just fork it and provide a PR. :)

Just be sure to check the token attribute on TodoistAPI instead of sync_token (which is a different thing).