Skip to content

Commit ab713f8

Browse files
Merge pull request #23 from thoughtspot/v.1.7.0
Change to TSRestApiV1.metadata_tml_import() per ThoughtSpot engineeri…
2 parents 5158c2c + 752c922 commit ab713f8

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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.6.1
3+
version = 1.7.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.6.1'
1+
__version__ = '1.7.0'

src/thoughtspot_rest_api_v1/tsrestapiv1.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,8 @@ def metadata_tml_export_string_with_associations_map(self, guid: str, formattype
10731073
return response_str, name_guid_map
10741074

10751075
# TML import is distinguished by having an {'Accept': 'text/plain'} header on the POST
1076+
# 'JSON' default actually takes a Python object representing JSON output
1077+
# Use 'YAML' or 'JSON_STR' as formattype if you have already stringified the input (read from disk etc.)
10761078
def metadata_tml_import(
10771079
self,
10781080
tml: Union[Dict, List[Dict]],
@@ -1090,22 +1092,28 @@ def metadata_tml_import(
10901092
tml_list = [tml]
10911093
else:
10921094
tml_list = tml
1095+
encoded_tmls = []
10931096

1097+
# Assume JSON is Python object
10941098
if formattype == 'JSON':
1095-
json_encoded_tml = json.dumps(tml_list)
1096-
elif formattype == 'YAML':
1097-
json_encoded_tml = json.dumps(tml_list)
1099+
for t in tml_list:
1100+
encoded_tmls.append(json.dumps(t))
1101+
# YAML or JSON_STR are already string when sent in
1102+
elif formattype in ['YAML', 'JSON_STR']:
1103+
for t in tml_list:
1104+
encoded_tmls.append(t)
10981105
# Assume it's just a Python object which will dump to JSON matching the TML format
10991106
else:
1100-
json_encoded_tml = json.dumps(tml_list)
1107+
for t in tml_list:
1108+
encoded_tmls.append(json.dumps(t))
11011109

11021110
import_policy = 'ALL_OR_NONE'
11031111

11041112
if validate_only is True:
11051113
import_policy = 'VALIDATE_ONLY'
11061114

11071115
post_data = {
1108-
'import_objects': json_encoded_tml,
1116+
'import_objects': str(encoded_tmls),
11091117
'import_policy': import_policy,
11101118
'force_create': str(create_new_on_server).lower()
11111119
}

0 commit comments

Comments
 (0)