AnsweredAssumed Answered

ListTables returns Database Synonyms and ListFields Does not recognize them

Question asked by matthysj on Jul 30, 2015
Latest reply on Jul 30, 2015 by matthysj

I am working in an enterprise SDE database.  I am working with a particular schema that contains tables, views and synonyms that have and have not been registered with the SDE and the Geodatabase.  Ultimately, I am trying to retrieve domains that are being used in the schema, but I have ran into an issue along the way.

The schema contains database synonyms.  I have found that arcpy.ListTables will return the database synonym, but arcpy.ListFields will not recognize the database synonym.  I would like to exclude the synonyms from my process, but arcpy.ListTables does not provide a utility to filter the return set by object type (info and dbase do not work in this case). 


Here is my specific example which I have abbreviated to highlight the issue.  The MYSCHEMA.RESERVOIR object is a database synonym:

tableList = arcpy.ListTables()
for table in tableList:    
   if "MYSCHEMA." in table:
       if "RESERVOIR" in table:
            print table
            fieldList = arcpy.ListFields(table) ## code breaks here
            print "made it here"
            for field in fieldList:
                 print table


Traceback (most recent call last):
  File "<pyshell#71>", line 6, in <module>
    fieldList = arcpy.ListFields(table)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\", line 1119, in ListFields
    return gp.listFields(dataset, wild_card, field_type)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\", line 344, in listFields
    self._gp.ListFields(*gp_fixargs(args, True)))
IOError: "MYSCHEMA.RESERVOIR" does not exist


So it appears that ListFields will not recognize a database synonym.  Does anyone have any thoughts about how to filter out database synonyms before running arcpy.ListFields?  I would prefer not to filter out the synonym objects by name, as these names could change and that would require someone to update the code.


Thanks in advance.

- Jake