I just upgraded my desktop machine to ArcGIS Pro 3.4 from 3.3.x, and noticed a change to the FeatureSharingDraft class tags property. After updating my cloned python environment, I was getting an error in one of my python scripts on the last line in this snippet:
sharing_draft = mp.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", sd_fs_name)
sharing_draft.summary = "my summary"
sharing_draft.tags = ["tag1", "tag2"]
sharing_draft.exportToSDDraft(sddraft)
The error was: Error exporting SD Draft: 'list' object has no attribute '_validateParameters'
When Pro 3.3.x was installed this error did not occur. Turns out it was the tags property - it cannot be a list, it must be a string with tags separated by a comma or semi-colon. Its strange that this property was always specified in the documentation to be a string, but I was using a list without error.
Just posting this in case anyone else has a similar issue.
Definitely thank you for this @ColForbin - I've been using this method since 1.x (or ever since they created the arcpy sharing module) to create sddrafts, stage the sd file, and upload same in order to keep our weekly Enterprise hosted feature layers current....
Here's how I've always done this in the Python IDLE if it helps anyone:
# Import system modules
import sys, os, arcpy, time, smtplib
from arcpy import env
from datetime import timedelta
# Local variables...
message = ""
current_time = time.asctime()
starting_time = time.time()
arcpy.SetLogHistory(False)
env.configKeyword= "DEFAULTS"
env.overwriteOutput = True
def stageSDDraft(mp,lyrName,summary,lyrs,descript,folder,tags,sdfolder):
sddraft_out = "C:/ArcProProjects3x/PortalUpdates/" + sdfolder + "/" + lyrName + ".sddraft"
draft = mp.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", lyrName, lyrs)
draft.portalFolder = folder
draft.tags = tags
##draft.allowExporting = True
draft.summary = summary
draft.description = descript
draft.overwriteExistingService = True
draft.exportToSDDraft(sddraft_out)
return
try:
portal = arcpy.SignInToPortal("https://webserver.ourorg.net/portal", "myUserName", "MyPassword")
aprx = arcpy.mp.ArcGISProject('C:/ArcProProjects3x/PortalUpdates/PortalUpdates.aprx')
for m in aprx.listMaps("Trans Layers"):
print("Map: " + m.name)
for lyr in m.listLayers():
if lyr.name == 'Thoroughfare':
lyrList = []
lyrList.append(m.listLayers(lyr.name)[0])
print(lyr.name)
stageSDDraft(m, lyr.name, "The Thoroughfare layer contains existing and planned roadways for Sarasota County, supporting a variety of transportation, evacuation and transportation planning efforts.",lyrList,
"The Thoroughfare layer contains existing and planned roadways for Sarasota County, supporting a variety of transportation, evacuation and transportation planning efforts",
"TransportationLayers","Transportation,Planning,Services,Safety","Transportation")
print(lyr.name + " Draft Created")
arcpy.StageService_server('C:/ArcProProjects3x/PortalUpdates/Transportation/' + lyr.name + '.sddraft', 'C:/ArcProProjects3x/PortalUpdates/Transportation/' + lyr.name + '.sd')
print(lyr.name + " Service Staged")
arcpy.UploadServiceDefinition_server('C:/ArcProProjects3x/PortalUpdates/Transportation/' + lyr.name + '.sd', 'My Hosted Services', "","","","","","OVERRIDE_DEFINITION","SHARE_ONLINE","PUBLIC",
"SHARE_ORGANIZATION","Transportation Layers Group")
print(lyr.name + " Service Uploaded")
message = message + "\n" + "1. " + (lyr.name) + " Service Uploaded"
So it looks like I am going to have to adjust my tags string here in the stageSDDraft:
"Transportation,Planning,Services,Safety"
to
"Transportation", "Planning", "Services", "Safety"
or to
["Transportation", "Planning", "Services", "Safety"]
@DavidColey actually, this: ["Transportation", "Planning", "Services", "Safety"] would fail. It should be:
"Transportation,Planning,Services,Safety"
So basically like I have the tags parameter currently formatted. Thanks @ColForbin
So you may find this interesting @ColForbin - when I tried to overwrite my layer like I detailed above, the
arcpy.UploadServiceDefinition_server('C:/ArcProProjects3x/PortalUpdates/Transportation/' + lyr.name + '.sd', 'My Hosted Services', "","","","","","OVERRIDE_DEFINITION","SHARE_ONLINE","PUBLIC", "SHARE_ORGANIZATION","Transportation Layers Group")
failed with five 9's - 99999 something unexpected....
Turns out that where I am specifying the group to be shared with, "Transportation Layers Group" in my case I now need to specify it as a list:
["Transportation Layers Group" ]
Once I did that, the Upload Service Definition method works