8000 groups.populate_users() only returns half of the users · Issue #197 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

groups.populate_users() only returns half of the users #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ugamarkj opened this issue Jun 8, 2017 · 3 comments
Closed

groups.populate_users() only returns half of the users #197

ugamarkj opened this issue Jun 8, 2017 · 3 comments

Comments

@ugamarkj
Copy link
ugamarkj commented Jun 8, 2017

I've noticed groups.populate_users() only populates half of the user items in the group. In the screenshot below you'll notice that there were 18 users that are returned by "len(group.users)", but it only looped through 9 of them. If I change it to loop from 0 to the length of the object, I'll get an out of range error. I'm either doing something wrong or this is a bug. Not sure if it is related to #141 . My code is below...

image

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import pypyodbc

#Set initial variables
tableauServerAddress = 'https://tableauserver'
userID = 'tableau'
pwFile = 'p.txt'

approvedIDs = []
with pypyodbc.connect('DSN=exasol') as conn: #Connect to Exasol
	with conn.cursor() as cur:

		cur.execute('''
			SELECT "EmployeeID" 
			FROM VIEWS_FINANCIAL."EmployeeCensusCurrent_vw" c
			WHERE c."GLDepartmentID" = '90635';
			''')

		data = cur.fetchall() #return records

		for x,r in enumerate(data):
			approvedIDs.append(r[0])

#read in password
pwf = open(pwFile)
pw = pwf.read()
pwf.close()

datasourceCredentials = TSC.ConnectionCredentials #Create object for embedding datasource credentials
datasourceCredentials.name = userID #Assumes the Tableau System account credentials
datasourceCredentials.password = pw
datasourceCredentials.embed = True

requests.packages.urllib3.disable_warnings(InsecureRequestWarning) #surpress SSL warning messages

tableau_auth = TSC.TableauAuth(userID, pw) #Set credentials
server = TSC.Server(tableauServerAddress) #create server object
server.add_http_options({'verify':False}) #ignore SSL self-cert
request_options = TSC.RequestOptions(pagesize=1000) #Set page size options

dictGroupUsers = {'UserName':[],'UserID':[]} #stores group users
dictUsers = {'UserName':[],'UserID':[]} 

with server.auth.sign_in(tableau_auth): #login to Tableau Server to get sites

	#create a list of all users on the server
	all_users = list(TSC.Pager(server.users, request_options))
	userList = []
	for user in all_users:
		dictUsers['UserName'].append(user.name)
		dictUsers['UserID'].append(user.id)


	#create a dictionary of all users in the group
	all_groups, pagination_item = server.groups.get(request_options)
	clinicalGroup = ''

	
	for group in all_groups :
		if group.name == 'Clinical Workbook Access': 
			clinicalGroup = group
			pagination_item = server.groups.populate_users(group,request_options)

			print('Checking authorization of {} current users:'.format(len(group.users)))
			#for r in range(0,len(group.users)):
			for user in group.users:
				#user = group.users[r]
				dictGroupUsers['UserName'].append(user.name)
				dictGroupUsers['UserID'].append(user.id)
				try:
					i = approvedIDs.index(user.name)
					print('     {} approved. no action needed.'.format(user.name))
				except:
					print('     {} not approved. removing...'.format(user.name))
					server.groups.remove_user(clinicalGroup, user.id)```

@graysonarts
Copy link
Contributor

Can you try printing out the pagination_item that is returned from the populate_users call? Also, would it be possible to get the output from the following bit of code inserted after the populate_users call:

import pprint
pprint.pprint(group.users)

@ugamarkj
Copy link
Author
ugamarkj commented Jun 9, 2017

In this pass there were 12 users in the group, but only 10 were looped through.

pagination_item:
<tableauserverclient.models.pagination_item.PaginationItem object at 0x0683FFF0>

pprint:
[<tableauserverclient.models.user_item.UserItem object at 0x06837790>,
<tableauserverclient.models.user_item.UserItem object at 0x06837850>,
<tableauserverclient.models.user_item.UserItem object at 0x06837910>,
<tableauserverclient.models.user_item.UserItem object at 0x06837970>,
<tableauserverclient.models.user_item.UserItem object at 0x06837A30>,
<tableauserverclient.models.user_item.UserItem object at 0x06837B50>,
<tableauserverclient.models.user_item.UserItem object at 0x06837BB0>,
<tableauserverclient.models.user_item.UserItem object at 0x06837C70>,
<tableauserverclient.models.user_item.UserItem object at 0x06837D90>,
<tableauserverclient.models.user_item.UserItem object at 0x06837DF0>,
<tableauserverclient.models.user_item.UserItem object at 0x06837EB0>,
<tableauserverclient.models.user_item.UserItem object at 0x06837F10>]

len(group.users) + print of each user.name:
Checking authorization of 12 current users:
117120 approved. no action needed.
151196 approved. no action needed.
116389 not approved. removing...
166318 approved. no action needed.
119007 approved. no action needed.
166917 approved. no action needed.
171596 approved. no action needed.
171734 approved. no action needed.
175448 not approved. removing...
183309 not approved. removing...

@ugamarkj
Copy link
Author

So after troubleshooting this more I figured out that the "server.groups.remove_user(clinicalGroup, user.id)" command alters the user items in "group.users", which is what caused the issue of not looping through each object. So I changed the code to build a separate list of all the users, then loop through that to do the remove user command. Closing this issue since it is apparently a user error on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0