Arcpy Script Error Message - Function had no effect

3189
17
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
17 Replies
DanPatterson_Retired
MVP Emeritus

your lines numbers quoted versus those in the original post aren't in sync  which lines exactly

In this line

userName = arcpy.Describe(workspace).connectionProperties.user.lower()

print(username)  # check the username versus the 'user'

# remove any datasets that are not owned by the connected user.

Add these two lines before the userDataList line

for ds in dataList:

    print(ds, ds.lower(), userName )


userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]

0 Kudos
AdityarajChavada
New Contributor III

Thanks again for your help, Dan! The following lines below commented out. 

# 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]

The reason is that we only have one data owner - GISUSER (all caps). Would it make sense to take the above lines out and directly pass the dataList variable to the tool? 

for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(workspace,dataset)
    dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()
0 Kudos
DanPatterson_Retired
MVP Emeritus

Why not try it, you are the only one that can test

0 Kudos
AdityarajChavada
New Contributor III

I tried it couple times and python crashes. See below.

0 Kudos
AdityarajChavada
New Contributor III

I printed the DataList and it is printing all the tables and feature classes (without the feature dataset in front). I believe the tool needs the inputdataset in the following format. Please correct me if I am wrong. 

Can this be added automatically in list? 

"user"+ "." + feature dataset" + "\" + user + "." + "feature class"

0 Kudos
AdityarajChavada
New Contributor III

Nevermind. I fixed the above issue by running repair on ArcGIS Desktop 10.4.1. Thank you for your support. 

RonnieRichards
Occasional Contributor III

We are experiencing this same issue when running the ESRI example code with python. We have been running this code for several years and this never used to happen. 

Performed a repair on the desktop install as Adityaraj Chavada mentioned above. This seemed to make Catalog work once and then it went back to reporting the "Function had no effect" error. 

We are on 10.7.1 . What finally worked for us was to upgrade our geodatabases from 10.5.1. -> 10.7.1 and the Analyze & Rebuild Indexes function worked as expected. Wish the tool would report such issues it is capable of knowing the GDB and software releases and should report this clearly to the administrator!!!

In past versions the maintenance tools were rather stable working between versions of the geodatabase but that seems to be a new scenario which needs to be tested in future upgrades. bummer.

ChrisCool
New Contributor II

Hi,

Having had the same problem and after studying the code, the problem comes from an error in the sample code from ESRI.
In fact, the first "." in the "find" function is too much!


Code before fix:
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]

Code after fix:
userDataList = [ds for ds in dataList if ds.lower().find("%s."% userName) > -1]

Chris

0 Kudos