@@ -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