question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in FeatureLayerCollection.query_domains

See original GitHub issue

In arcgis python api version 1.6.2, the FeatureLayerCollection.query_domains method generates an error. For example:

item = gis.content.get('ITEM_ID')
flc = FeatureLayerCollection.fromitem(item)
flc.query_domains([0])

produces this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-31345fbf23ab> in <module>
----> 1 flc.query_domains([0])

~/anaconda3/envs/geo/lib/python3.7/site-packages/arcgis/features/layer.py in query_domains(self, layers)
   1908 
   1909         """
-> 1910         if not isinstance(layers (tuple, list)):
   1911             raise ValueError("The layer variable must be a list.")
   1912         url = "{base}/queryDomains".format(base=self._url)

TypeError: 'list' object is not callable

The error appears to be caused by a missing comma after layers in line 1910 of layer.py.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mikiekellycommented, Dec 20, 2019

As a workaround you can access domains this way:

from arcgis.gis import GIS


def process_layers_or_tables(layer_or_table):
    print(f'{layer_or_table.properties.name}: {layer_or_table.url}')
    for field in layer_or_table.properties.fields:
        print(f'\t{field.name} - {field.alias} - {field.type}')
        if 'domain' in field and field.domain is not None:
            print(f'\t\tDomain associated with field')
            if field.domain.type == 'codedValue':
                for coded_value in field.domain.codedValues:
                    print(f'\t\t\t{coded_value.name}')
            else:
                print(f'Not coded value domain: {field.domain}')


gis = GIS()

feature_layer = gis.content.get('90cf22bcbb30499c912264f5305be5b8')

for layer in feature_layer.layers:
    process_layers_or_tables(layer)

for table in feature_layer.tables:
    process_layers_or_tables(table)
0reactions
jlishnunncommented, Dec 20, 2019

Thank you @mikiekelly

I re-purposed your function to create a list of coded domain values

def layer_or_table_domain_values(layer_or_table, field_name):
    arcpy.AddMessage(f'{layer_or_table.properties.name}: {layer_or_table.url}')
    field_names = [field.name for field in layer_or_table.properties.fields]
    arcpy.AddMessage(field_names)
    for field in layer_or_table.properties.fields:
        if field_name == field.name:
            arcpy.AddMessage(field.name)
            if 'domain' in field and field.domain is not None:
                arcpy.AddMessage('Domain associated with field')
                if field.domain.type == 'codedValue':
                    domain_values = [coded_value.name for coded_value in field.domain.codedValues]
                    arcpy.AddMessage(domain_values)
                else:
                    arcpy.AddMessage(f'Not coded value domain: {field.domain}')
Read more comments on GitHub >

github_iconTop Results From Across the Web

What's new in version 2.0.0 | ArcGIS API for Python
FeatureLayerCollection. Fixes BUG-000134934 where query_domains() fails with The requested layer (layerId: queryDomains) was not found. (Error Code: 400).
Read more >
featureLayerCollection overwrite "Job failed" - Esri Community
Hi. I am trying to update/overwrite a hosted feature layer, following the logic given near the end of a tutorial on learn.arcgis (...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found