Fix for issue #60#61
Fix for issue #60#61t8y8 merged 3 commits intotableau:developmenttableau/server-client-python:developmentfrom t8y8:60-delete-sign-outt8y8/server-client-python:60-delete-sign-outCopy head branch name to clipboard
Conversation
| # Deleting the site also signs you out on the Server. | ||
| # Here we check that you're deleting the site you are signed in to | ||
| # (Which is true now but may not always be) and then clear auth tokens | ||
| if site_id == self.parent_srv._site_id: |
There was a problem hiding this comment.
we have a property getter on the parent_srv object. Why not use that instead of the internal member?
There was a problem hiding this comment.
The getter checks if you have a site_id, which we don't because we remove it in the DELETE call when we make it, and then complains that you aren't signed in.
@property
def site_id(self):
if self._site_id is None:
error = 'Missing site ID. You must sign in first.'
raise NotSignedInError(error)
return self._site_id
There was a problem hiding this comment.
We clear the auth info (token and site_id) after this check. This code is in the delete method.
| def sign_out(self): | ||
| url = "{0}/{1}".format(self.baseurl, 'signout') | ||
| # If there are no auth tokens you're already signed out. No-op | ||
| if not self.parent_srv._auth_token: |
There was a problem hiding this comment.
This feels like it should be a method on the server object to indicate if it is signed in. Looking at what you wrote, I understand that there is no "private" in python but we should honor things when they make sense. A method on the server liked signed_in() which returns a boolean would feel cleaner.
There was a problem hiding this comment.
When you say "signed in" are you just defining that as having a token?
The token isn't guaranteed to be valid just because it exists (the crux of this issue) which means you aren't actually 'signed in' -- but if that's ok I can have something like that
There was a problem hiding this comment.
That is what I am saying. Our logic right now is that we assume if we have a token we are signed in. You still might fail because the token expired or something else, but from the client's standpoint, we think we are signed in. The exact same check you are doing ... just move it so we are not accessing private member variables.
| logger.info('Deleted single site (ID: {0})'.format(site_id)) | ||
| # Deleting the site also signs you out on the Server. | ||
| # Here we check that you're deleting the site you are signed in to | ||
| # (Which is true now but may not always be) and then clear auth tokens |
There was a problem hiding this comment.
This comment doesn't make sense, "Which is true now". Our code does not enforce this. It might be true that this only works in this case but I think you can leave that out. Simply put if you delete the site you are signed into, you are automatically signed out.
There was a problem hiding this comment.
Tableau Server enforces this, you MUST be signed into the site you are deleting or you get a 403 that says "You can't delete a resource on another site"
There was a problem hiding this comment.
Okay. But the comment is confusing given where it is in the code and that level of detail is not needed unless we were doing the check before we called delete. Then it would make sense. As it is, our check is doing "If we deleted the site we are logged into, then we are automatically logged out". That is what this comment should say. If you want to add a check before we call the server, you could but I don't think it is needed right now. That check could have this comment
…d fix a bug in test setup
| # If we deleted the site we are logged into | ||
| # then we are automatically logged out | ||
| if site_id == self.parent_srv.site_id: | ||
| self.parent_srv._clear_auth() |
|
🚀 Just the one request for an extra line of logging. Looks good to me |
Make Sign Out a no-op when you are already signed out.
Here is a repro script that passes after and fails before the change: