I am just in a minor shock here. After upgrading to ArcGIS Pro 2.0, suddenly an ArcMap / Pro compatible ArcPy application I have been working on for a long time stopped working. Upon examination of my code, I came to the conclusion it was related to the 'connectionProperties' property of workspaces. Prior to 2.0, this was read/write in ArcPy. Now, in 2.0, examining the Help and judging the code failure, it seems to have become read only... (Workspace properties—ArcPy Functions | ArcGIS Desktop). This is a breaking API change!
My tool, and probably a lot of scripts by other users, depends on the ability to set the connectionProperties. This is a debilitating limitation introduced in 2.0, that seriously curtails what you can do with ArcPy in Pro 2.0 and above in terms of management of connection properties. Why-oh-why did ESRI change this? If it is because to many people were wrecking their connection properties because they were to inexperienced with ArcPy or un-careful when using this powerful option, then ESRI should educate their users, not remove the option and silently change the API.
Minor update: it seems you can still update the connection properties on layer files (*.lyrx), by using the "updateConnectionProperties" method on LayerFile:
LayerFile—ArcPy | ArcGIS Desktop
Changing my code for one of the failing scripts from:
conProp['connection_info']['database'] = newFileGDB
newProLyr.connectionProperties = conProp
to:
conProp['connection_info']['database'] = newFileGDB
newProLyr.updateConnectionProperties(newProLyr.connectionProperties,conProp)
fixed at least one tool.
I still need to evaluate others.
And another update after a bit more investigation:
The "dataSource" property of the Layer class also seems to have become Read Only. However, you can use the "updateConnectionProperties" on the same class to solve this:
This upgrade to 2.0 definitely needs some changes!
I'm glad you raised this because I am encountering the issue of the Layer class method no longer being Read and Write too. Unfortunately, in my case I don't think the "updateConnectionProperties" method can be used to restore my workflow.
The coding pattern that I need to work or workaround is:
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\temp\test.aprx")
mapx = aprx.listMaps("Map")[0]
lyr = mapx.listLayers("Test Layer")[0]
lyr.dataSource = r"C:\temp\test.gdb\testFC2"
I see you managed to work out a solution, as you posted it on GISStackExchange.
Yes, in general, I think all workflows can still be accomodated. It just requires figuring out how to work with lyr.updateConnectionProperties() and specifically how to manipulate the dictionary returned by lyr.connectionProperties.
However, I agree some of this has become a bit less intuitive...
Hmm, it seems some Help pages still need updating for Pro 2.0, the
Updating and fixing data sources—ArcPy | ArcGIS Desktop
page still lists "connectionProperties" as a valid way to modify connection properties, while the Workspace and Layer Help pages, now clearly list this property as "Read Only", and my experience showed it to be so.
The new paradigm is clearly using "updateConnectionProperties" only for this kind of modifications to data sources.
I may have missed it, even though I have tried to keep up with news and blog about Pro, but it might be nice to see some Blog article about these changes related to updating and fixing data sources in Pro 2.0 versus previous releases.
You have the makings of a good blog already Marco