nylas / sync-engine

:incoming_envelope: IMAP/SMTP sync system with modern APIs
https://nylas.com/docs/platform
GNU Affero General Public License v3.0
3.5k stars 354 forks source link

./bin/inbox-console -e some@email.foo leads to an exception if no OAuth token is set on it #439

Open alexanderadam opened 7 years ago

alexanderadam commented 7 years ago

I wanted to remove an account because ./bin/inbox-auth some@email.foo --reauth creates duplicates and I obviously wanted to get rid of these.

So I tried to enter the console with ./bin/inbox-console -e some@email.foo as described. But it seems that one (the first account) doesn\t have the OAuth token set and this results in the following exception:

Traceback (most recent call last):
  File "./bin/inbox-console", line 31, in <module>
    console()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 488, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 474, in main
    self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 659, in invoke
    ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 325, in invoke
    return callback(*args, **kwargs)
  File "./bin/inbox-console", line 27, in console
    start_console(email_address)
  File "/opt/sync-engine/inbox/console.py", line 63, in start_console
    user_console(user_email_address)
  File "/opt/sync-engine/inbox/console.py", line 38, in user_console
    with writable_connection_pool(account.id, pool_size=1).get()\
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/opt/sync-engine/inbox/crispin.py", line 181, in get
    client = self._new_connection()
  File "/opt/sync-engine/inbox/crispin.py", line 235, in _new_connection
    conn = self._new_raw_connection()
  File "/opt/sync-engine/inbox/crispin.py", line 232, in _new_raw_connection
    account, self._should_timeout_connection())
  File "/opt/sync-engine/inbox/auth/oauth.py", line 34, in connect_account
    self._authenticate_IMAP_connection(account, conn)
  File "/opt/sync-engine/inbox/auth/gmail.py", line 61, in _authenticate_IMAP_connection
    token = g_token_manager.get_token_for_email(account)
  File "/opt/sync-engine/inbox/models/backends/gmail.py", line 81, in get_token_for_email
    return self.get_token(account, GOOGLE_EMAIL_SCOPE, force_refresh)
  File "/opt/sync-engine/inbox/models/backends/gmail.py", line 77, in get_token
    gtoken = self._get_token(account, scope, force_refresh=force_refresh)
  File "/opt/sync-engine/inbox/models/backends/gmail.py", line 63, in _get_token
    gtoken = account.new_token(scope)
  File "/opt/sync-engine/inbox/models/backends/gmail.py", line 244, in new_token
    raise OAuthError("No valid tokens")
inbox.basicauth.OAuthError: No valid tokens

I'm using sync engine 17.1.6.

My workaround was for now:

./bin/get-object --account-id 1
obj.mark_deleted
obj.disable_sync("account deleted")
db_session.commit()

and finally ./bin/delete-account-data 1