Skip to content

Commit ec56c10

Browse files
V.1.3.0 adds the export_fqn= option to the /metadata/tml/export methods, and an override to turn it off if you are on an older cluster (feature starts in 8.9)
1 parent 6a20989 commit ec56c10

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ You create a TSRestApiV2 object with the `server_url` argument, then use the `se
123123
## TML operations
124124
One primary use case of the REST APIs is to import and export ThoughtSpot Modeling Language (TML) files.
125125

126+
### Disabling FQN export
127+
ThoughtSpot 8.9 adds the 'export_fqn' option to the `/metadata/tml/export` endpoint, which includes the GUID references to all related objects in an exported TML file. Because this is very useful, the library defaults to including the argument set to true in all TML Export methods.
128+
129+
Older versions of ThoughtSpot will not support this option, so there is a global `can_export_fqn` flag to disable it. Set it to False if you are encountering errors and are on a version prior to 8.9:
130+
131+
ts: TSRestApiV1 = TSRestApiV1(server_url=server)
132+
ts.can_export_fqn = False
133+
126134
### Retrieving the TML as a Python OrderedDict from REST API
127135
If you want to use the TML classes to programmatically adjust the returned TML, there is a `export_tml(guid)` method which retrieves the TML from the API in JSON format and then returns it as a Python OrderedDict.
128136

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = thoughtspot_rest_api_v1
3-
version = 1.2.6
3+
version = 1.3.0
44
description = Library implementing the ThoughtSpot V1 REST API
55
long_description = file: README.md
66
long_description_content_type = text/markdown
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.6'
1+
__version__ = '1.3.0'

src/thoughtspot_rest_api_v1/tsrestapiv1.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def __init__(self, server_url: str):
176176
# V2 REST API for basic implementation
177177
self.v2_base_url = '{server}/tspublic/rest/v2/'.format(server=self.server)
178178

179+
# Flag for whether the version implements the export_fqn option of metadata/tml/export
180+
self.can_export_fqn = True
181+
179182
#
180183
# Session management calls
181184
# - up here vs. in the SESSION section below (because these two are required)
@@ -963,7 +966,7 @@ def raise_tml_errors(response: requests.Response) -> Dict:
963966
else:
964967
return response.json()
965968

966-
def metadata_tml_export(self, guid: str, export_associated=False) -> OrderedDict:
969+
def metadata_tml_export(self, guid: str, export_associated=False, export_fqn=True) -> OrderedDict:
967970
# Always returns a Python Dict, converted from a request to the API to receive in JSON
968971
endpoint = 'metadata/tml/export'
969972

@@ -972,6 +975,9 @@ def metadata_tml_export(self, guid: str, export_associated=False) -> OrderedDict
972975
'formattype': 'JSON',
973976
'export_associated': str(export_associated).lower()
974977
}
978+
# Added in version 8.9, can be set to skip for older releases
979+
if self.can_export_fqn is True:
980+
post_data['export_fqn'] = str(export_fqn).lower()
975981

976982
url = self.base_url + endpoint
977983
# TML import is distinguished by having an {'Accept': 'text/plain'} header on the POST
@@ -997,7 +1003,7 @@ def metadata_tml_export(self, guid: str, export_associated=False) -> OrderedDict
9971003
return tml_obj
9981004

9991005
# Method to retrieve the all of the associate objects and retrieve original object and a dict of name:guid mapping
1000-
def metadata_tml_export_with_associations_map(self, guid: str) -> (OrderedDict, Dict):
1006+
def metadata_tml_export_with_associations_map(self, guid: str, export_fqn=True) -> (OrderedDict, Dict):
10011007
# Always returns a Python Dict, converted from a request to the API to receive in JSON
10021008
endpoint = 'metadata/tml/export'
10031009

@@ -1006,6 +1012,9 @@ def metadata_tml_export_with_associations_map(self, guid: str) -> (OrderedDict,
10061012
'formattype': 'JSON',
10071013
'export_associated': 'true'
10081014
}
1015+
# Added in version 8.9, can be set to skip for older releases
1016+
if self.can_export_fqn is True:
1017+
post_data['export_fqn'] = str(export_fqn).lower()
10091018

10101019
url = self.base_url + endpoint
10111020
# TML import is distinguished by having an {'Accept': 'text/plain'} header on the POST
@@ -1030,7 +1039,8 @@ def metadata_tml_export_with_associations_map(self, guid: str) -> (OrderedDict,
10301039

10311040
return tml_obj, name_guid_map
10321041

1033-
def metadata_tml_export_string(self, guid: str, formattype: str = 'YAML', export_associated=False) -> str:
1042+
def metadata_tml_export_string(self, guid: str, formattype: str = 'YAML',
1043+
export_associated=False, export_fqn=True) -> str:
10341044
# Intended for a direct pull with no conversion
10351045
endpoint = 'metadata/tml/export'
10361046
# allow JSON or YAML in any casing
@@ -1040,6 +1050,9 @@ def metadata_tml_export_string(self, guid: str, formattype: str = 'YAML', export
10401050
'formattype': formattype,
10411051
'export_associated': str(export_associated).lower()
10421052
}
1053+
# Added in version 8.9, can be set to skip for older releases
1054+
if self.can_export_fqn is True:
1055+
post_data['export_fqn'] = str(export_fqn).lower()
10431056
url = self.base_url + endpoint
10441057

10451058
# TML import is distinguished by having an {'Accept': 'text/plain'} header on the POST
@@ -1062,7 +1075,8 @@ def metadata_tml_export_string(self, guid: str, formattype: str = 'YAML', export
10621075
else:
10631076
raise Exception()
10641077

1065-
def metadata_tml_export_string_with_associations_map(self, guid: str, formattype: str = 'YAML') -> (str, Dict):
1078+
def metadata_tml_export_string_with_associations_map(self, guid: str, formattype: str = 'YAML',
1079+
export_fqn=True) -> (str, Dict):
10661080
# Intended for a direct pull with no conversion
10671081
endpoint = 'metadata/tml/export'
10681082
# allow JSON or YAML in any casing
@@ -1072,6 +1086,9 @@ def metadata_tml_export_string_with_associations_map(self, guid: str, formattype
10721086
'formattype': formattype,
10731087
'export_associated': 'true'
10741088
}
1089+
# Added in version 8.9, can be set to skip for older releases
1090+
if self.can_export_fqn is True:
1091+
post_data['export_fqn'] = str(export_fqn).lower()
10751092
url = self.base_url + endpoint
10761093

10771094
# TML import is distinguished by having an {'Accept': 'text/plain'} header on the POST

0 commit comments

Comments
 (0)