Skip to content

UserItem.email field is always None #565

Closed

Description

@RyanSnodgrass

There is no way to populate the UserItem.email field on a get request.

Using the .get() all users method:

import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('https://SERVERURL')

with server.auth.sign_in(tableau_auth):
    all_users, pagination_item = server.users.get()
    for user_item in all_users:
        print("User name: '{}' fullname: '{}', User email: '{}'".format(user_item.name,
                                                                  user_item.fullname,
                                                                  user_item.email))

# =>
# User name: 'username123' fullname: 'None', User email: 'None'
# User name: 'username124' fullname: 'None', User email: 'None'
# User name: 'username125' fullname: 'None', User email: 'None'
# User name: 'username126' fullname: 'None', User email: 'None'

Using the .get_by_id() at least returns the fullname field, but still no email:

user_item = server.users.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
print("User name: '{}' fullname: '{}', User email: '{}'".format(user_item.name,
                                                                user_item.fullname,
                                                                user_item.email))
# =>
# User name: 'username123' fullname: 'User Name 123', User email: 'None'

This is caused by the default return from the REST API
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_users_on_site
and see here from the list of fields
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_fields.htm#get-users_site

Using the ?fields= url param in the REST API could return the missing UserItem fields. However it seems at this time the TableauServerClient currently does not support adding fields to the request param.

Activity

  1. RyanSnodgrass commented on Feb 7, 2020

    @RyanSnodgrass
    Author

    It seems maybe the _make_request() method in the Endpoint class has support for parameters

    def _make_request(self, method, url, content=None, request_object=None,

  2. RyanSnodgrass commented on Feb 7, 2020

    @RyanSnodgrass
    Author

    I'm trying to hack my way through this.

    # If I could edit the .baseurl for the .get() method, then maybe that
    # would work? Alas, cannot edit an attribute
    url = server.users.baseurl
    url_with_fullname = url + '?fields=_all_'
    server_response = server.users.get_request(url_with_fullname, None)
    all_user_items = TSC.UserItem.from_response(server_response.content,
                                                server.users.parent_srv.namespace)
    print("User name: '{}' fullname: '{}', User email: '{}'".format(all_user_items[0].name,
                                                                    all_user_items[0].fullname,
                                                                    all_user_items[0].email))
    
    # =>
    # User name: 'username123' fullname: 'User Name', User email: 'user.name@email.com'

    This actually works!

  3. RyanSnodgrass commented on Feb 7, 2020

    @RyanSnodgrass
    Author

    Feature request to add the fields we want returned from the .get() and .get_by_id() methods.

  4. RyanSnodgrass commented on Feb 7, 2020

    @RyanSnodgrass
    Author

    Do you think changing the baseurl to have the _all_ fields by default is a good idea?

    My opinion is I find it annoying that the UserItem object returns different fields based on which get method you use. Nevermind that one field never returns.

    Personally, I don't see much difference with only 2 more short fields(email and fullname) added to the object memory space. And even then most times developers are going to be using the pagination feature.

  5. RyanSnodgrass commented on Feb 10, 2020

    @RyanSnodgrass
    Author
    # If I could edit the .baseurl for the .get() method, then maybe that
    # would work? Alas, cannot edit an attribute
    url = server.users.baseurl
    url_with_fullname = url + '?fields=_all_'
    server_response = server.users.get_request(url_with_fullname, None)
    all_user_items = TSC.UserItem.from_response(server_response.content,
                                                server.users.parent_srv.namespace)
    print("User name: '{}' fullname: '{}', User email: '{}'".format(all_user_items[0].name,
                                                                    all_user_items[0].fullname,
                                                                    all_user_items[0].email))
    
    # =>
    # User name: 'username123' fullname: 'User Name', User email: 'user.name@email.com'

    I've found this only brings back the first 100 results due to the API's pagination.

  6. hariszhr commented on Mar 19, 2020

    @hariszhr

    I m writing a production software, and need to update email and full name in some cases. This bug causes me to update those fields everytime, since those fields return 'None'.
    I probably shouldnt hack my way through it. Waiting for a fix....

  7. shinchris commented on Dec 18, 2020

    @shinchris
    Contributor

    See #278 for updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions