I need to buffer a subset of features in a particular feature class. To do this, I am first creating a feature layer (using a SQL query to select only what I want), and then running Buffer. So my ArcPy script includes this little function to buffer my handful of feature classes:

def funcBuffer(inFeature, outFeature, bufDist, querySQL):
    arcpy.MakeFeatureLayer_management(inFeature, "tempLayer", querySQL)
    arcpy.Buffer_analysis("tempLayer", outFeature, bufDist, "FULL", "ROUND", "ALL", "")

This works perfectly on most of my feature classes. However, there is one that fails. The Python error is:
ERROR 000230: Failed selecting with "OH_UG" = 'UG'

The help page for that error suggests that the SQL query is invalid. However,

  • the field OH_UG exists, and there are some features with the value "UG"
  • it successfully validates in Query Builder
  • I can use it to Select by Attribute with no problem (python snippet from within ArcMap: arcpy.SelectLayerByAttribute_management("TransmissionLines","NEW_SELECTION","OH_UG = 'UG'"))
  • similarly structured queries work on other feature classes

I've tried different ways of passing the SQL query and all fail: '"OH_UH" = \'UG\'', 'OH_UH = \'UG\'', """ "OH_UG" = 'UG' """

I revised the script to do the selection after making the feature layer:

def funcBuffer(inFeature, outFeature, bufDist, querySQL):
    arcpy.MakeFeatureLayer_management(inFeature, "tempLayer")
    arcpy.SelectLayerByAttribute_management("tempLayer", "NEW_SELECTION", querySQL)
    arcpy.Buffer_analysis("tempLayer", outFeature, bufDist, "FULL", "ROUND", "ALL", "")

and now MakeFeatureLayer works, but SelectLayerByAttribute throws ERROR 000358: Invalid expression -- still a complaint regarding invalid SQL.

I attempted to select using a different (numeric) field in the table, and am still getting the same 000358 error.

So I am not sure what's going wrong -- is it the SQL, is it the particular feature class, is it gremlins? How can I work around the problem in ArcPy?

  • Background server threw an exception usually means the tool caused a crash. Just curious, if you disable BG and run the same tool /w same settings, does ArcMap crash? – KHibma Aug 28 '14 at 13:18
  • Have you tried running the select analysis tool in ArcMap and exporting the result as a python snippet. Generally I don't recommend using the export but it may give insight to how it passes the SQL query and you may be able to copy it. – landocalrissian Aug 28 '14 at 13:23
  • @KHibma -- I just turned off background processing to check, and it successfully ran. (Which I don't think is necessarily because of the tool running in the background, there's probably something else contributing [Arc got rebooted between the 00143 error and now])... – Erica Aug 28 '14 at 13:54
  • @ChrisR It's sending it within triple quotes: arcpy.Select_analysis("TransmissionLines","C:/temp/scratch.shp",""""OH_UG" = 'UG'""") – Erica Aug 28 '14 at 14:02
  • Are all the feature classes you are testing coming from the same geodatabase? – papadoo Aug 29 '14 at 20:35

After over a week of attempting to debug this, a colleague used it on his computer.... and it consistently worked fine.

Turns out his SDE connection had different permissions and the feature in question was in a database which was restricted to read-only for me, but not for him. When we copied that SDE connection to my machine, I could run the script without problems.

Why exactly this would cause a problem, I am still not sure. There are no geoprocessing tools trying to act on the original data, it just makes a copy -- but changing that solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.