In ArcPy 3.7 (ArcPro 2.9 environment), I am looking to promote an Aprx from one environment to another, changing datasets accordingly. I am using layer.updateConnectionProperties to switch from QA SDE layers to Prod SDE layers. This works as expected for the layers, themselves, but I cannot get the related table (also SDE based) to also update to Prod data sources.
auto_update_joins_and_relates doesn't work, nor does spelling out the new environmental parameters by updating the connection properties dictionary.
currentDb = QA_SDE
outputDb = Prod_SDE
currentEnv = QA_RegisteredDir
outputEnv = Prod_RegisteredDir
inputAprx = QA_Aprx
targetAprx = Prod_Aprx
aprx = arcpy.mp.ArcGISProject(inputAprx)
maps = aprx.listMaps()
for map in maps:
layers = map.listLayers()
for layer in layers:
if not layer.supports('dataSource'):
continue
elif currentDb in layer.dataSource:
newProps = layer.connectionProperties
oldProps = layer.connectionProperties
newProps['connection_info']['db_connection_properties'] = outputDb
newProps['connection_info']['instance'] = 'sde:sqlserver:' + outputDb
newProps['connection_info']['server'] = outputDb
newProps['connection_info']['authentication_mode'] = 'OSA'
if 'relates' in layer.connectionProperties:
if isinstance(newProps['relates'], list):
newProps['relates'][0]['connection']['connection_info']['db_connection_properties'] = outputDb
newProps['relates'][0]['connection']['connection_info']['instance'] = 'sde:sqlserver:' + outputDb
newProps['relates'][0]['connection']['connection_info']['server'] = outputDb
newProps['relates'][0]['connection']['connection_info']['authentication_mode'] = 'OSA'
layer.updateConnectionProperties(current_connection_info = oldProps, new_connection_info = newProps, auto_update_joins_and_relates = True)
elif currentEnv in layer.dataSource:
layer.updateConnectionProperties(current_connection_info = currentEnv, new_connection_info = outputEnv)
aprx.saveACopy(targetAprx)
When run, newProps dictionary updates accordingly to reflect the Prod sourced related table. However, when updateConnectionProperties is run, the layer source is in Prod but the relate is still QA sourced. This behavior occurs both when auto_update_joins_and_relates is set to True and to False.
What am I missing here?