AnsweredAssumed Answered

MakeTableView loses definition query

Question asked by don.morrison on Sep 21, 2020
Latest reply on Sep 21, 2020 by don.morrison

In my python code that generates mxd files, I changed the name of one of my table views from 'Organizations' to 'Organization' and later discovered that the table view's definition query became blank with that change. To make it even stranger, this only happens if arcpy.env.workspace is set to my enterprise database (None and a file geodatabase work OK).  I expect I'll have to open a problem with ESRI, but thought I'd log it here in case anybody else stumbles on it. This is a very severe error for me since the definition query filters sensitive data out of the view - at least when it is working as designed. An obvious workaround is to name it something other than "Organization" but it does shake my confidence that I can trust that the sensitive data will always get filtered out appropriately.

 

Here is the test code that reproduces the problem

import os
import arcpy
DB_PATH = r'C:/Users/dmorri28/Documents/ArcGIS/Projects/MyProject/CC-SQL2k16-ERC-SDE.sde'
DB_TABLE = os.path.join(DB_PATH, 'ROW_Habitat.SDE.Program')
TITLES = ['DummyTitle', 'Organization', 'Org']
WORKSPACES = [None, DB_PATH, arcpy.env.scratchWorkspace]

def run_test (workspace, title):
print ('***********************************')
print ('Workspace: %s' % workspace)
print ('Title: %s'% title)

arcpy.env.workspace = workspace
arcpy.MakeTableView_management(DB_TABLE, title, "Org_ID = 'FM'")

table_view = arcpy.mapping.TableView(title)
print ("Table view query: %s" % (str(table_view.definitionQuery)))

arcpy.Delete_management(title, 'TableView')
if __name__ == '__main__':
for workspace in WORKSPACES:
for title in TITLES:
run_test(workspace, title)

Here is the output - notice how on the fifth test the query is empty.

***********************************
Workspace: None
Title: DummyTitle
Table view query: Org_ID = 'FM'
***********************************
Workspace: None
Title: Organization
Table view query: Org_ID = 'FM'
***********************************
Workspace: None
Title: Org
Table view query: Org_ID = 'FM'
***********************************
Workspace: C:/Users/dmorri28/Documents/ArcGIS/Projects/MyProject/CC-SQL2k16-ERC-SDE.sde
Title: DummyTitle
Table view query: Org_ID = 'FM'
***********************************
Workspace: C:/Users/dmorri28/Documents/ArcGIS/Projects/MyProject/CC-SQL2k16-ERC-SDE.sde
Title: Organization
Table view query:
***********************************
Workspace: C:/Users/dmorri28/Documents/ArcGIS/Projects/MyProject/CC-SQL2k16-ERC-SDE.sde
Title: Org
Table view query: Org_ID = 'FM'
***********************************
Workspace: None
Title: DummyTitle
Table view query: Org_ID = 'FM'
***********************************
Workspace: None
Title: Organization
Table view query: Org_ID = 'FM'
***********************************
Workspace: None
Title: Org
Table view query: Org_ID = 'FM' 

I was able to reproduce this on two different systems.  I'm running this on Python 2.7. I'm also using ArcMap 10.6.1.

Outcomes