Select to view content in your preferred language

Unexplained error when updating hosted feature layer domains: "{'code': 500, 'message': "ERROR: Domain does not exist: '㛨㫀ȃ'", 'details': []}"

78
1
11 hours ago
Labels (1)
hnewell
Emerging Contributor

I seem to have a solution for this, at least for the time being, but want to document this possible bug/unusual behavior.

I wrote a script to update some domains of a hosted feature service on an Enterprise Portal, call it "Seed_Collection". My code (see attached example csv, names changed for privacy):

import arcgis
from arcgis.gis import GIS

feature_id = "<my feature ID>"

gis = arcgis.gis.GIS("Pro")

feature_conn = gis.content.get(feature_id)
pops_conn = feature_conn.layers[0]

personnel = pd.read_csv("seed_collection_personnel.csv")

domain = [{"name":p, "code":p} for p in personnel.Personnel]

update = {
    "fields":[
        {
            "name": "observer",
            "domain": {
                "name": "personnel",
                "type": "codedValue",
                "codedValues":domain
            }
        }
    ]
}

attempt = pops_conn.manager.update_definition(update)
if(attempt["success"]):
    print("Update successful!")
else:
    print("Update failed :(")

It worked fine for the first few runs, but a couple weeks later one of the domain updates failed with the following exception:

{'code': 500, 'message': "ERROR: Domain does not exist: '㛨㫀ȃ'", 'details': []}

I checked the and found that the domain name in the hosted feature service had changed from the original name it was published from ArcGIS Pro with, "personnel," to "Seed_Collection_personnel." So I changed the domain name to the new name in my update JSON, copied and pasted directly from the service properties. My code now looked like:

import arcgis
from arcgis.gis import GIS

feature_id = "<my feature ID>"

gis = arcgis.gis.GIS("Pro")

feature_conn = gis.content.get(feature_id)
pops_conn = feature_conn.layers[0]

personnel = pd.read_csv("seed_collection_personnel.csv")

domain = [{"name":p, "code":p} for p in personnel.Personnel]

update = {
    "fields":[
        {
            "name": "observer",
            "domain": {
                "name": "Seed_Collection_personnel",
                "type": "codedValue",
                "codedValues":domain
            }
        }
    ]
}

attempt = pops_conn.manager.update_definition(update)
if(attempt["success"]):
    print("Update successful!")
else:
    print("Update failed :(")

Same error, different string of characters:

{'code': 500, 'message': "ERROR: Domain does not exist: 'ϸ੫Ǩ'", 'details': []}

After lots of hair-pulling, I tried removing the domain name from the update JSON entirely, just to see what would happen. So my update JSON now looked like:

update = {
    "fields":[
        {
            "name": "observer",
            "domain": {
                # "name": "Seed_Collection_personnel",
                "type": "codedValue",
                "codedValues":domain
            }
        }
    ]
}

 

Predictably, this failed with the following exception:

{'code': 500, 'message': 'Database error has occurred.', 'details': []}

BUT, AFTER running the code with the domain_name removed, my previous code (second code chunk) ran successfully. I was able to resolve this problem for three different fields in three different layers, all originally published with the same "personnel" domain.

So, fixed for now 🎉. But very curious if anyone has any insight or solutions that don't require intentionally supplying an invalid JSON before supplying the correct one, in case it happens again. Thanks!

0 Kudos
1 Reply
Clubdebambos
MVP Regular Contributor

Hi @hnewell,

I have found that when it comes to updating fields you are better off getting the full current field definition first, manipulating the property you want to update, and then using the full definition to update the layer. I have commented the updates below.

import arcgis
from arcgis.gis import GIS

feature_id = "<my feature ID>"

## THE FIELD NAME
field_name = "observer"

gis = arcgis.gis.GIS("Pro")

feature_conn = gis.content.get(feature_id)
pops_conn = feature_conn.layers[0]

personnel = pd.read_csv("seed_collection_personnel.csv")

domain = [{"name":p, "code":p} for p in personnel.Personnel]

## GET THE FIELD DEFINITION AS A DICTIONARY
field = [dict(f) for f in pops_conn.properties.fields if f["name"] == field_name][0]

## UPDATE THE DOMAIN CODEDVALUES
field["domain"]["codedValues"] = domain

## UPDATE DICTIONARY FOR update()
update = {
    "fields":[field]
}

attempt = pops_conn.manager.update_definition(update)
if(attempt["success"]):
    print("Update successful!")
else:
    print("Update failed :(")

Let us know if that helps.

All the best,

Glen

~ learn.finaldraftmapping.com
0 Kudos