Hi,
Did you find a solution to this? I'm developing some code in Arcpro 3.1.3 and I too get the same vague error. I've tried running it in the python command line window as well as notebook. I've also saved the project, re-opened it with the layer in it and tried running the code below. The layer exists, so its not a broken layer,there is sensible data in it and SubNetID field exists. If I go to the Symbology panel in ArcPro and set it to unique value, subnetid, then it all uniquely colours so I know the dataset is OK. Dare I say it that ESRI have somehow broken this with an update?
My code is simply:
aprx = arcpy.mp.ArcGISProject("Current")
aprxMap = aprx.listMaps("Map")[0]
layer = aprxMap.listLayers('Sub1000_3')[0] # This layer was initially loaded into the map as a single symbol
aSymbology = layer.symbology
aSymbology.updateRenderer('UniqueValueRenderer')
aSymbology.renderer.fields = ["SubNetID"]
p = arcpy.mp.ArcGISProject("CURRENT")
cr = p.listColorRamps("Basic Random")[0]
aSymbology.colorRamp = cr
layer.symbology = aSymbology
It fails on line 6 with
NameError: The attribute 'fields' is not supported on this instance of UniqueValueRenderer.
Trying to think out of the box, you could argue the renderer has not been given any values to render but it seems to be a chicken and egg situation, how can I give it values when the first step is to say which field you want to render on, but its that line it fails on!
I've tagged a few of python gurus into this to see if they can identify the issue: @DanPatterson_Retired , @curtvprice , @XanderBakker , @jcarlson , @JoshuaBixby