Problems accessing GlobalID from an arcpy.da.SearchCursor

4140
8
11-30-2012 12:32 PM
by Anonymous User
Not applicable
Hello all,

I'm trying to use a search cursor to query GlobalID values from a feature class or table using the arcpy.da module's search cursor class.  It seems, however, that this is not supported.  I have tried the following:

>>> cur = arcpy.da.SearchCursor(featureclass,["globalid"])
>>> row = cur.next()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: unsupported field type GLOBALID #11



>>> cur = arcpy.da.SearchCursor(featureclass,["globalid@"])
>>> row = cur.next()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
RuntimeError: A column was specified that does not exist. 


I've tried all variations of letter cases (globalid, GlobalID, and GLOBALID), and it seems to make no difference.  I've tried requesting all fields for the feature class or table that I'm searching by providing ["*"] for the fields list, but the globalid field is not included in the resulting row data.

The following does work, however, if I use the non-'da' version of the SearchCursor class:

>>> cur = arcpy.SearchCursor(featureclass)
>>> row = cur.next()
>>> row.globalid
u'{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}'
>>> row.getValue("globalid")
u'{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}'


There doesn't seem to be any problem with a regular GUID type field...only with Global ID fields that have been added through the Add Global IDs geodatabse tool.  Is this a known limitation of the new data access module cursors, and/or is there some a more appropriate way to access global IDs through the arcpy.da module?  I don't really have a problem with using the other versions of the search cursors, but my interpretation from the documentation was that the cursors provided by the da module are more efficient...and this also makes me wonder if I should avoid querying Global IDs if there is a deliberate reason that they cannot be accessed with the new cursors.
Tags (2)
0 Kudos
8 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Mike,

This is a bug and has been logged:

NIM084842:  Support GlobalID field type with arcpy.da.SearchCursor.


You can follow the status of this bug on support.esri.com.
0 Kudos
TomWayson
Esri Contributor
Until the bug w/ arcpy.da.SearchCursor is fixed, and since you are concerned about efficiency, you may want to modify the arcpy.SearchCursor code to limit the fields returned by setting the Fields option to limit the fields returned to the GlobalID:

>>> cur = arcpy.SearchCursor(featureclass, fields="GlobalID")
0 Kudos
MalcolmParnell2
New Contributor
Hi Mike,
This is a bug and has been logged:
NIM084842:  Support GlobalID field type with arcpy.da.SearchCursor.
You can follow the status of this bug on support.esri.com.


Which, nearly 12 months down the track, has no status update.

And as for just restricting the field to the GlobalID - that doesn't help. The example given above uses the old cursor (which didn't have this problem), not the new da version.

We haven't tried 10.2 yet - can anyone verify this is still a problem? I presume from the (lack of) status update that it is.
0 Kudos
XanderBakker
Esri Esteemed Contributor
We haven't tried 10.2 yet - can anyone verify this is still a problem? I presume from the (lack of) status update that it is.


Hi Malcolm,

Using 10.2 the problem seems to be solved:

fc = 'name of fc in TOC'
cur = arcpy.da.SearchCursor(fc,["GlobalID"])
row = cur.next()
print row[0]


returns:
{24CBF943-A07F-463E-AFFA-EB1AD760E29E}

Kind regards,

Xander
0 Kudos
MichaelAdornetto1
New Contributor II

This doesn't appear fixed in 10.4.1 in 2017,

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I don't have access to a 10.4.1 machine at the moment, but I just tested the code from xander_bakker‌'s Nov. 5, 2013 comment using ArcGIS 10.5 and it works.

MichaelAdornetto1
New Contributor II

Weird, I tested it again, using your code,  but it throws an exception in 10.4.1.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Out of curiosity, what is the error message text?

0 Kudos