Hi,
I am trying to iterate over all layers in a map to see the datasources, and as it is recommended it is good to see
if hasattr(layer, "dataSource"):
pass
if the layer has attribute dataSource, but the problem is on basemap, it givers an error which is:
NameError: The attribute 'dataSource' is not supported on this instance of Layer.
I do not understand this errors, because it should skip the basemap because it does not have dataSource.
Is anyone has any explanation for this issue?
Solved! Go to Solution.
I assume you are talking about Pro and not ArcMap here. If so, the explanation is, it's a defect. I logged a defect over a year ago for likely what is the same issue you are dealing with, but they have set it low priority, so I am not expecting them to address it any time soon.
#BUG-000128367 Using the Python method hasattr() produces different error messages when used in ArcMap (10.7.1) versus ArcGIS Pro (2.5 Beta)
Hi, how is your layer derived? Can you do a describe on the layer then use hasattr?
I tried to use Describe, but it says
data_source_list=[]
'''
I have several maps, I want to iterate over all layers.
'''
for map_ in this_project.listMaps():
for layer in map_.listLayers():
desc=arcpy.Describe(layer)
if hasattr(desc, "dataSource"):
if not desc.dataSource in data_source_list:
pass
'''data_spurce_list.append(desc)'''
'''out put'''
RuntimeError: Object: Describe input value is not valid type
It looks like describe does not accept layer.
I assume you are talking about Pro and not ArcMap here. If so, the explanation is, it's a defect. I logged a defect over a year ago for likely what is the same issue you are dealing with, but they have set it low priority, so I am not expecting them to address it any time soon.
#BUG-000128367 Using the Python method hasattr() produces different error messages when used in ArcMap (10.7.1) versus ArcGIS Pro (2.5 Beta)
Yes I got the error with ArcPro version 2.8.0.
I agree with you, I think it is a bug with the function.