Invert where clause error on Select by attributes

904
6
07-07-2020 09:16 AM
CassidyKillian
Occasional Contributor

I am running a script that was exported directly from model builder in Pro.  It runs this select by attributes statement and gives me an error.

# Process: Select Layer By Attribute (Select Layer By Attribute)
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'", invert_where_clause="")

Traceback (most recent call last):
File "H:\Python\HydrantRepairPro.py", line 25, in <module>
Model()
File "H:\Python\HydrantRepairPro.py", line 16, in Model
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'", invert_where_clause="")
TypeError: SelectLayerByAttribute() got an unexpected keyword argument 'invert_where_clause'

Does anyone know why the invert  where cause is throwing an error?

0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

Are you using Pro?  The parameter in question is only supported in Pro.

0 Kudos
CassidyKillian
Occasional Contributor

I built the model in pro and exported to a python script that I need to run as a scheduled task.  When I tried to run the script in IDLE it gave me the error.

0 Kudos
DanPatterson
MVP Honored Contributor

The options for that parameter are

inert_where_clause
(Optional)

Specifies whether the result of the expression should be inverted.

  • NON_INVERT The result of the query will be used as is. This is the default.
  • INVERT The result of the query will be inverted. If the selection_type parameter is used, the inversion occurs before the selection is combined with existing selections.

not "".  Leave it out altogether if NON_INVERT is what you want.  You don't need to specify parameters if you are using named parameters and using defaults.


... sort of retired...
CassidyKillian
Occasional Contributor

Dan,

I removed the invert clause statement so not it looks like this:

# Process: Select Layer By Attribute (Select Layer By Attribute)
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'")

Now it gives me this error:

Traceback (most recent call last):
File "H:\Python\HydrantRepairPro.py", line 25, in <module>
Model()
File "H:\Python\HydrantRepairPro.py", line 16, in Model
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'")
File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 7737, in SelectLayerByAttribute
raise e
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).

0 Kudos
JoeBorgione
MVP Esteemed Contributor

I think you need to add a make feature layer step in there.  This is a case where the model to python conversion isn't 100%.

This line in the error is the kicker:

The value cannot be a feature class
can't wait to retire....
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

As an FYI, the trackback is showing you are running the code from ArcGIS Desktop/ArcMap and not Pro, which is why your original code failed because of the parameter difference.  Also, it could be why the code is failing now since Select Layer By Attribute handled data set inputs differently between ArcMap and Pro.

Run the original code from Python bundled with Pro.