Script only works in IDE and not Desktop/Server

208
2
Jump to solution
04-10-2019 12:32 PM
MollyFoley
Regular Contributor

I have two scripts; one only works in the IDE, one works fine in the IDE and Desktop but then fails when trying to run from the server. I am getting fed up with the misleading errors or non-descriptive, vague errors. 

First, the one that only works in the IDE and not Desktop. I keep getting an error on using the CreateRelationshipClass_management tool:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000177: Relationship classes can only be created in the same database that contains the feature classes or tables

The issue with this is that when I print my export paths and ensure that the things I am creating a relationship with both are in the same geodatabase, they are:

C:\Users\mfoley10\Documents\ArcGIS\scratch\HabitatData.gdb\MgmtTracts
C:\Users\mfoley10\Documents\ArcGIS\scratch\HabitatData.gdb\MgmtTractAttrb

This is the code that is apparently causing this error:

arcpy.CreateRelationshipClass_management(os.path.join(exportPath, "MgmtTracts"), 
os.path.join(exportPath, "MgmtTractAttrb"), 'TractAttrbRelationship', 'COMPOSITE',
'Tract2Attrb', 'Attrb2Tract', 'NONE', 'ONE_TO_MANY', 'NONE', 'MgmtTractID',
'MgmtTractID')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

So what is with the error message? It makes no sense. 

Second script runs fine in IDE and Desktop, but fails at the server level. The only error message I get in the results window is literally "Failed." No other details, absolutely nothing. That is entirely useless. There is absolutely no reason my script should be able to run in both the IDE and Desktop and not be able to run on Server. I checked what the code looks like on server and it looks perfectly normal. When I analyze before publishing, there is nothing listed as an error or warning. I have completely deleted the service out of my Server and republished - doesn't work.

Edit: Looking at the server log, there is a more descriptive error message, saying that the index is out of range for ListTableViews call on a map document that it is editing. The line of code it is erroring on has been newly added since the last publication of the GP service, so I am wondering if the map document hasn't updated to include it? The map document is located in a registered folder, so I assumed if I saved the map document on my main machine, it would update in the registered folder on the server machine automatically. Is that not the case? I can't install Desktop on the server to check, so I'm kind of SOL in terms of seeing. Edit 2: I copied the changed MXDs to the server's registered folder and the service started working. So basically, my registered folder isn't really registered even though it is validated as a data store when I check via server properties... pretty sure that's not how registered folders are supposed to work?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

If you do:

print(arcpy.env.workspace)

what are the results from within the IDE and the application?

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

If you do:

print(arcpy.env.workspace)

what are the results from within the IDE and the application?

View solution in original post

MollyFoley
Regular Contributor

Good call. I set the workspace later in the script to make the zip file. If I move it to before the creation of the relationship, then it works! Thank you so much!! You likely have saved me many hours of anguish today.

New script:

arcpy.env.workspace = exportPath
arcpy.CreateRelationshipClass_management(os.path.join(exportPath, "MgmtTracts"),
os.path.join(exportPath, "MgmtTractAttrb"), 'TractAttrbRelationship', 'COMPOSITE',
'Tract2Attrb', 'Attrb2Tract', 'NONE', 'ONE_TO_MANY', 'NONE', 'MgmtTractID',
'MgmtTractID')‍‍‍‍