Python tool hasBeenValidated is always False

323
4
Jump to solution
02-24-2020 06:45 AM
DonMorrison1
Occasional Contributor III

I've developed a number of python toolbox tools and my latest has a problem that I can't figure out.  It works fine when I run it from my ArcPro tool folder, but not when it is run as a shared geoprocessing package downloaded from ArcGIS Online

After inserting log statements I see that the root of the problem is that the hasBeenValidated setting on the input parameters is always False for all of the parameters. Nothing I do in the UI results in a True setting. I have 2 parameters that interact based on hasBeenValidated. When parameter A has not been validated, I repopulate the list associated with parameter B and set its value to the first element in the list.  But since parameter A always shows up a not validated, it is impossible to make stick any change to parameter B.

This is only happening in 2 of my tools - the unique thing about them is that parameter A is a GPFeatureLayer.  These are the only 2 tools with that type of parameter.  hasBeenValidated is a readonly value so I don't see how anything I do has any control over it but without it I don't see how I can make the tool work correctly.

I'm running this on ArcPro  2.4.3  and Python 3.6.8 and Advanced license.

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor III

The ESRI team confirmed that this is a bug. The hasBeenValidated attribute is not set correctly when a tool is run from a geoprocessing package. I'm waiting to see if I can get a bug number for tracking.  

I was actually able to workaround it by saving  the parameter values in a global space when exiting updateParameters. Then on the next call to updateParameters I do two things:

1) for those parameters that might change, I compare the incoming parameter value to the saved value to determine if it changed

2) for the filter lists (the user can not change these) I restore the incoming parameter value to the saved value

I can explain more if anybody is really interested

View solution in original post

4 Replies
DonMorrison1
Occasional Contributor III

I went back and checked and hadBeenValidated is never True for any parameter in any of my shared tools.  So forget about the speculation that it has something to do with the GPFeatureLayer parameter. 

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Don, there is a fuzzy section on tool validation code for web tools.

Authoring web tools with Python scripts—ArcGIS Pro | Documentation 

whether it applies seems to depend on what you are trying to validate

0 Kudos
DonMorrison1
Occasional Contributor III

Thanks Dan - I just read through that - fuzzy indeed. This particular tool is being packaged as a "geoprocessing package" - so instead of running on the server, I upload it to ArcGIS Online where users can download it and run it on their ArcPro desktop. It has its own consolidation and validation quirks just like the web tools which run on the server.  I've been doing some more digging and I see that geoprocessing package that I build includes both the original code (.pyt and .py files) plus a .tbx file which I believe is a "custom toolbox".  It's when I run the tool out of the custom toolbox that the hasBeenValidated setting is never set to True.  When I run the tool out of the original code it works OK.  Tomorrow I'm attending a 2-day ESRI Midwest User Conference - maybe I can track somebody down that can explain this. 

0 Kudos
DonMorrison1
Occasional Contributor III

The ESRI team confirmed that this is a bug. The hasBeenValidated attribute is not set correctly when a tool is run from a geoprocessing package. I'm waiting to see if I can get a bug number for tracking.  

I was actually able to workaround it by saving  the parameter values in a global space when exiting updateParameters. Then on the next call to updateParameters I do two things:

1) for those parameters that might change, I compare the incoming parameter value to the saved value to determine if it changed

2) for the filter lists (the user can not change these) I restore the incoming parameter value to the saved value

I can explain more if anybody is really interested