Select to view content in your preferred language

MakeTableView loses definition query

642
1
Jump to solution
09-21-2020 09:45 PM
DonMorrison1
Frequent Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Frequent Contributor

It appears that it "fails" if there is a table in the workspace with the same name as the name of the table view being created (out_view).  I have a table called Organization in my enterprise database (but not DummyTitle or Org). I also have a table called Program and sure enough when I created a table view with that name, the definition query came out blank.  So I guess that explains it - I really think it should throw an error in this case it the definition query can not be preserved.

View solution in original post

0 Kudos
1 Reply
DonMorrison1
Frequent Contributor

It appears that it "fails" if there is a table in the workspace with the same name as the name of the table view being created (out_view).  I have a table called Organization in my enterprise database (but not DummyTitle or Org). I also have a table called Program and sure enough when I created a table view with that name, the definition query came out blank.  So I guess that explains it - I really think it should throw an error in this case it the definition query can not be preserved.

0 Kudos