Arcpy Script Error Message - Function had no effect

1607
16
01-21-2018 12:58 AM
AdityarajChavada
New Contributor III

Hi,

We are using ArcGIS Desktop 10.4 with Python 2.7.10. 

We trying to automate the task of rebuilding the indexes on tables/feature classes owned by the user account part of the regular multi-user geodatabase maintenance. We can rebuild the indexes on the user tables manually without any problems using Data Owner account. However, when using the python script example provided in the Esri's help - Rebuild Indexes—Help | ArcGIS Desktop (pasted below),

# Import system modules
import arcpy, os

# set workspace
workspace = "E:/sde/SDE_Data_Owner.sde"

# set the workspace environment
arcpy.env.workspace = workspace

# NOTE: Rebuild indexes can accept a Python list of datasets.

# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()

# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(workspace,dataset)
    dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()

# reset the workspace
arcpy.env.workspace = workspace

# Get the user name for the workspace
userName = arcpy.Describe(workspace).connectionProperties.user.lower()

# remove any datasets that are not owned by the connected user.
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]

# Execute rebuild indexes
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", userDataList, "ALL")
print('Rebuild Complete')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Unfortunately, the python script throws following error message for line 33 above. I feel that it is not liking the userDataList variable? 

Any assistance in resolving this would be appreciated. 

Thank you.

Tags (3)
0 Kudos
16 Replies
DanPatterson_Retired
MVP Esteemed Contributor

does the username exist? y

ou should throw a print statement in to see if it is matches one of yours

0 Kudos
AdityarajChavada
New Contributor III

Hi Dan!

Yes, the username exists. I tried using the Print Statement.The username in my GDB is GISUSER (all caps). Perhaps, the making it lower case is throwing it off?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Have you printed out the userDataList to make sure:  1) it is populated, and 2) it is populated correctly?

0 Kudos
AdityarajChavada
New Contributor III

Thanks for your reply, Joshua! So, I printed out the userDataList and it says []. Does this mean the list is empty? 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Yes, you have an empty list, thus the function has "no effect."

AdityarajChavada
New Contributor III

Is there any way to correct the script to correctly populate the list?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

see my previous post and check the affect that 'lower' has on the tests as well.

Print statements are cheap, but make sure you are printing what is being passed into your tests since you are changing text case in places

DanPatterson_Retired
MVP Esteemed Contributor

[] is an empty list, so you had better back up a few lines and see where the empty lists are being passed.  Also, the list would be empty if the index had already been rebuilt and doesn't need rebuilding for that user

AdityarajChavada
New Contributor III

Okay. I printed the dataList and it is printing the entire list. Does that mean that line 26 and 29 are creating issues with list. So, when I try to pass this dataList directly to the tool (after commenting line 26 and 29), python freezes and crashes. 

0 Kudos