server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

ownerName filter does not return items for workbooks, datasources, flows, projects, views, metrics

Open jorwoods opened this issue 4 years ago • 4 comments

Describe the bug Providing the owerName filter to an endpoint never returns any items.

Versions Details of your environment, including:

  • Tableau Server Version - 2020.3.8, 2021.3.0
  • Python Version - 3.8.10
  • Tableauserverclient version - 0.16.0

To Reproduce EDIT: Edited the reproduction code to reflect more handling of commas and spaces. None of the combinations produced yield a result.

from itertools import product
import os

from dotenv import load_dotenv
import tableauserverclient as TSC

load_dotenv()

server = TSC.Server(os.environ["SERVER_ADDRESS"], True)
auth = ...

server.auth.sign_in(auth)


prefix_domain = lambda name, domain: f'{domain}\\{name}'
suffix_domain = lambda name, domain: f'{name}@{domain}'
just_name = lambda name, domain: name


# Comma treatments
remove_comma = lambda name: name.replace(',', '')
first_last = lambda name: ' '.join(name.split(', ')[::-1])
url_encode_comma = lambda name: name.replace(',', '%2C')
backslash_comma = lambda name: name.replace(',', '\\,')
backslash_url_escaped_comma = lambda name: name.replace(',', '\\%2C')
url_encode_escape_comma = lambda name: name.replace(',', '%5C%2C')
no_op = lambda name: name

# Space treatments
remove_space = lambda name: name.replace(' ', '')
url_encode_space = lambda name: name.replace(' ', '%20')
url_encode_escape_space = lambda name: name.replace(' ', '%5C%20')
url_encode_plus_space = lambda name: name.replace(' ', '+')
url_encode_plus_escape_space = lambda name: name.replace(' ', '%5C+')

user: TSC.UserItem = server.users.get_by_id(server.user_id)
email = user.email
username = user.name
domain = user.domain_name

formats = [prefix_domain, suffix_domain, just_name]
user_names = [user.fullname, email, username]
#         control
commas = [no_op, remove_comma, first_last, url_encode_comma, backslash_comma, backslash_url_escaped_comma, url_encode_escape_comma]
#         control
spaces = [no_op, remove_space, url_encode_space, url_encode_escape_space, url_encode_plus_space, url_encode_plus_escape_space]
#                 control
string_methods = [str.strip, str.capitalize, str.casefold, str.lower, str.title, str.upper]
endpoints = ['workbooks'] #, 'projects', 'datasources', 'flows', 'views']

for combo in product(formats, user_names, commas, spaces, string_methods, string_methods, endpoints):
    # edit - Added check for case sensitivity on domain
    func, name, comma, spaces, method, dom_method, endpoint = combo
    name = comma(name)
    name = method(name)
    name = spaces(name)
    dom = dom_method(domain)
    name = func(name, dom)
    
    reqopts = TSC.RequestOptions()
    reqopts.filter.add(
        TSC.Filter(
            TSC.RequestOptions.Field.OwnerName,
            TSC.RequestOptions.Operator.Equals,
            name
        )
    )

    endpoint = getattr(server, endpoint)
    try:
        items, _ = endpoint.get(reqopts)
    except TSC.ServerResponseError:
        continue
    if len(items) > 0:
        print(name)

Results No results are ever printed, yet at least some combination of that should work.

NOTE: Be careful not to post user names, passwords, auth tokens or any other private or sensitive information.

jorwoods avatar Oct 02 '21 16:10 jorwoods