@@ -299,9 +299,10 @@ class PlotlyDict(dict):
299
299
def __init__ (self , * args , ** kwargs ):
300
300
class_name = self .__class__ .__name__
301
301
302
- for src in ('xsrc' , 'ysrc' ):
303
- if src in kwargs and isinstance (kwargs [src ], Column ):
304
- kwargs [src ] = self ._assign_id_to_src (src , kwargs [src ])
302
+ for key in kwargs :
303
+ if utils .is_source_key (key ):
304
+ #if src in kwargs and isinstance(kwargs[src], Column):
305
+ kwargs [key ] = self ._assign_id_to_src (key , kwargs [key ])
305
306
306
307
super (PlotlyDict , self ).__init__ (* args , ** kwargs )
307
308
if issubclass (NAME_TO_CLASS [class_name ], PlotlyTrace ):
@@ -314,20 +315,43 @@ def __init__(self, *args, **kwargs):
314
315
"a user interface." )
315
316
316
317
def __setitem__ (self , key , value ):
318
+
317
319
if key in ('xsrc' , 'ysrc' ):
318
320
value = self ._assign_id_to_src (key , value )
319
321
320
322
return super (PlotlyDict , self ).__setitem__ (key , value )
321
323
322
324
def _assign_id_to_src (self , src_name , src_value ):
323
- if isinstance (src_value , Column ):
324
- if src_value .id == '' :
325
+ if isinstance (src_value , basestring ):
326
+ src_id = src_value
327
+ else :
328
+ try :
329
+ src_id = src_value .id
330
+ except :
331
+ err = ("{} does not have an `id` property. "
332
+ "{} needs to be assigned to either an "
333
+ "object with an `id` (like a "
334
+ "plotly.grid_objs.Column) or a string. "
335
+ "The `id` is a unique identifier "
336
+ "assigned by the Plotly webserver "
337
+ "to this grid column." )
338
+ src_value_str = str (src_value )
339
+ err = err .format (src_name , src_value_str )
340
+ raise exceptions .InputError (err )
341
+
342
+ if src_id == '' :
343
+ if isinstance (src_value , Column ):
325
344
err = exceptions .COLUMN_NOT_YET_UPLOADED_MESSAGE
326
345
err .format (column_name = src_value .name , reference = src_name )
327
346
raise exceptions .InputError (err )
328
347
else :
329
- src_value = src_value .id
330
- return src_value
348
+ err = ("{} should be a unique identifier "
349
+ "string assigned by the Plotly "
350
+ "server to this to this grid column, "
351
+ "not an empty string." .format (src_name ))
352
+ raise exceptions .InputError (err )
353
+
354
+ return src_id
331
355
332
356
def update (self , dict1 = None , ** dict2 ):
333
357
"""Update current dict with dict1 and then dict2.
0 commit comments