@@ -229,8 +229,8 @@ def _create_descriptor_file(self, items, max_attachments_per_data_row=None):
229229 >>> {DataRow.row_data:"http://my_site.com/photos/img_01.jpg"},
230230 >>> {DataRow.row_data:"/path/to/file1.jpg"},
231231 >>> "path/to/file2.jpg",
232- >>> {"tileLayerUrl" : "http://", ...}
233- >>> {"conversationalData " : [ ...], ...}
232+ >>> {DataRow.row_data: { "tileLayerUrl" : "http://", ...} }
233+ >>> {DataRow.row_data: {"type " : ..., 'version' : ..., 'messages' : [...]} }
234234 >>> ])
235235
236236 For an example showing how to upload tiled data_rows see the following notebook:
@@ -258,7 +258,7 @@ def _create_descriptor_file(self, items, max_attachments_per_data_row=None):
258258
259259 def upload_if_necessary (item ):
260260 row_data = item ['row_data' ]
261- if os .path .exists (row_data ):
261+ if isinstance ( row_data , str ) and os .path .exists (row_data ):
262262 item_url = self .client .upload_file (row_data )
263263 item ['row_data' ] = item_url
264264 if 'external_id' not in item :
@@ -341,40 +341,39 @@ def validate_keys(item):
341341 "`row_data` missing when creating DataRow." )
342342
343343 invalid_keys = set (item ) - {
344- * {f .name for f in DataRow .fields ()}, 'attachments'
344+ * {f .name for f in DataRow .fields ()}, 'attachments' , 'media_type'
345345 }
346346 if invalid_keys :
347347 raise InvalidAttributeError (DataRow , invalid_keys )
348348 return item
349349
350+ def formatLegacyConversationalData (item ):
351+ messages = item .pop ("conversationalData" )
352+ version = item .pop ("version" )
353+ type = item .pop ("type" )
354+ if "externalId" in item :
355+ external_id = item .pop ("externalId" )
356+ item ["external_id" ] = external_id
357+ if "globalKey" in item :
358+ global_key = item .pop ("globalKey" )
359+ item ["globalKey" ] = global_key
360+ validate_conversational_data (messages )
361+ one_conversation = \
362+ {
363+ "type" : type ,
364+ "version" : version ,
365+ "messages" : messages
366+ }
367+ item ["row_data" ] = one_conversation
368+ return item
369+
350370 def convert_item (item ):
351- # Don't make any changes to tms data
352371 if "tileLayerUrl" in item :
353372 validate_attachments (item )
354373 return item
355374
356375 if "conversationalData" in item :
357- messages = item .pop ("conversationalData" )
358- version = item .pop ("version" )
359- type = item .pop ("type" )
360- if "externalId" in item :
361- external_id = item .pop ("externalId" )
362- item ["external_id" ] = external_id
363- if "globalKey" in item :
364- global_key = item .pop ("globalKey" )
365- item ["globalKey" ] = global_key
366- validate_conversational_data (messages )
367- one_conversation = \
368- {
369- "type" : type ,
370- "version" : version ,
371- "messages" : messages
372- }
373- conversationUrl = self .client .upload_data (
374- json .dumps (one_conversation ),
375- content_type = "application/json" ,
376- filename = "conversational_data.json" )
377- item ["row_data" ] = conversationUrl
376+ formatLegacyConversationalData (item )
378377
379378 # Convert all payload variations into the same dict format
380379 item = format_row (item )
@@ -386,11 +385,7 @@ def convert_item(item):
386385 parse_metadata_fields (item )
387386 # Upload any local file paths
388387 item = upload_if_necessary (item )
389-
390- return {
391- "data" if key == "row_data" else utils .camel_case (key ): value
392- for key , value in item .items ()
393- }
388+ return item
394389
395390 if not isinstance (items , Iterable ):
396391 raise ValueError (
0 commit comments