@@ -1073,6 +1073,8 @@ def metadata_tml_export_string_with_associations_map(self, guid: str, formattype
1073
1073
return response_str , name_guid_map
1074
1074
1075
1075
# 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.)
1076
1078
def metadata_tml_import (
1077
1079
self ,
1078
1080
tml : Union [Dict , List [Dict ]],
@@ -1090,22 +1092,28 @@ def metadata_tml_import(
1090
1092
tml_list = [tml ]
1091
1093
else :
1092
1094
tml_list = tml
1095
+ encoded_tmls = []
1093
1096
1097
+ # Assume JSON is Python object
1094
1098
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 )
1098
1105
# Assume it's just a Python object which will dump to JSON matching the TML format
1099
1106
else :
1100
- json_encoded_tml = json .dumps (tml_list )
1107
+ for t in tml_list :
1108
+ encoded_tmls .append (json .dumps (t ))
1101
1109
1102
1110
import_policy = 'ALL_OR_NONE'
1103
1111
1104
1112
if validate_only is True :
1105
1113
import_policy = 'VALIDATE_ONLY'
1106
1114
1107
1115
post_data = {
1108
- 'import_objects' : json_encoded_tml ,
1116
+ 'import_objects' : str ( encoded_tmls ) ,
1109
1117
'import_policy' : import_policy ,
1110
1118
'force_create' : str (create_new_on_server ).lower ()
1111
1119
}
0 commit comments