I've created a model in ArcGIS Pro ModelBuilder which attempts to carry out the following:

  1. Variable: Database connection (sql server)
  2. Make Query Layer (input = Database Connection, output = "Dwellings SQL")
  3. Make Feature Layer (input = "Dwellings SQL", output = "Dwellings")

Then using the code in the following resource:


I created a toolbox which should publish (overwrite) a layer called "Dwellings" in our AGOL account. I have tweaked the code in the ScriptTool function as such:

def ScriptTool(map, service, summary, tags, description, overwriteService, enableEditing, enableSync, enableWFS, timezone, share_public, share_organization, share_groups, outdir):
"""ScriptTool function docstring"""

# Set output file names
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps(map)[0]
selected_layer = m.listLayers()[0]

# Create FeatureSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", service, [selected_layer])
sharing_draft.summary = summary
sharing_draft.tags = tags
sharing_draft.description = description
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"
sharing_draft.overwriteExistingService = overwriteService

# Create Service Definition Draft file
outsddraft = sddraft_output_filename
arcpy.AddMessage("Service definition draft created")

# Modify capabilities
if enableEditing or enableSync:
    ModifyCapabilities(sddraft_output_filename, enableEditing, enableSync)
if enableWFS:

# Set time zone
if(timezone != ""):
    property_set = [{
        "key": "dateFieldsRespectsDayLightSavingTime",
        "value": "true"
            "key": "dateFieldsTimezoneID",
            "value": timezone
    SetTimezone(sddraft_output_filename, property_set=property_set)

# Create Service Definition file
sd_filename = service + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
arcpy.AddMessage("Service definition created")

# Upload to portal
output = arcpy.UploadServiceDefinition_server(sd_output_filename, "My Hosted Services", in_override="OVERRIDE_DEFINITION", in_public=share_public, in_organization=share_organization, in_groups=share_groups)
arcpy.AddMessage("Service published")

return output[5]

...so that the function will publish a feature layer rather than the whole map. On running the code I receive the following error:

File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1179, in StageService raise e File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1176, in StageService retval = convertArcObjectToPythonObject(gp.StageService_server(*gp_fixargs((in_service_definition_draft, out_service_definition, staging_version), True))) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 512, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Selected layer does not contain a required layer type for web feature layer","object":"Map"}]). Failed to execute (StageService).

Failed script Publish Web Feature Layer... Failed to execute (Publish Web Feature Layer).

I can't understand why this is happening as the current map does display the imported feature layer and when running the section of the code under #Reference map to publish in the python console it does find the "Dwellings" feature layer. The line of code which throws the error is:

arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

...and the error message isn't very helpful, I can't find any helpful documentation on Esri's website which details if the problem is with the feature layer or a bug in the code.

I am using ArcGIS Pro 3.1.3 with the default arcgispro-py3 environment.

Below is a diagram of my model:

Model Diagram

Below are the parameters I used as per the Esri article:

Model Parameters

1 Answer 1


I exported the model to a python file in an attempt to better understand the steps that ArcGIS Pro was taking to execute the code. It seemed to utilise multiple "with" statements to set environmental variables and I wasn't sure whether or not these variables would persist outside the with statements. I tidied the code up but I was still receiving the same error.

I wondered if as part of the Analyzer checks ArcGIS Pro wasn't able to publish query layers rather than feature classes so I utilised the:


...function in order to create a feature class that would be stored in the project geodatabase. Again, I was receiving the same error.

I then had the idea that although arcpy was able to select a visible layer on the currently open map, maybe when it came to publishing the layer the Analyzer would require the project file to be saved before proceeding. I added the:


...command into the ScriptTool() function and this seemed to resolve the issue (it would be handy for this to have been detailed in the error message returned by the Analyzer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.