[Cubicweb] Misunderstanding of dataimport _create_copyfrom_bufferfunction

Dimitri Papadopoulos Orfanos dimitri.papadopoulos at cea.fr
Tue May 20 12:29:22 CEST 2014


The definition of the CubicWeb function _create_copyfrom_buffer() in
cubicweb/dataimport.py looks like this:
	def _create_copyfrom_buffer(..., replace_sep=None):

This function is then repeatedly called from MassiveObjectStore methods
in dataio/dataimport.py:
	_create_copyfrom_buffer(..., replace_sep=self.replace_sep)
where self.replace_sep is initlaized in __init__() as the empty string ''.

Clearly there is a discrepancy between two "special values": None and
empty string ''. These two special values are handled differently by the
existing if's. I believe:
* the code should standardize on a single special value for readability,
* the if's should nevertheless be fixed to process special values in a
consistent way.


Le 19/05/2014 14:24, LANQUETUIT Cyril a écrit :
> Hello,
> In function _create_copyfrom_buffer of file dataimport.py, in the
> following part of code:
> /
>                         # If a replace_sep is given, replace
>                         # the separator instead of returning None
>                         # (and thus avoid empty buffer)
>                         if replace_sep:
>                             value = value.replace(_char, replace_sep)
>                         else:
>                             return/
> when the separator is set to '' (the default value when MassiveObjectStore is used for store)
> the replace_sep is evaluate to false so the else clause is executed, the function _create_copyfrom_buffer return an empty buffer
> then this following error is raised:
> /File "/home/cl239099/cubicweb/cubes/dataio/dataimport.py", line 831, in flush_entities
>     raise ValueError('Error in buffer creation for etype %s' % etype)
> ValueError: Error in buffer creation for etype Question/
> I don't understand exactly what the code should do or should be but if the clause
> /
> if replace_sep:/
> is replaced by something like
> /
> if (replace_sep != None):
> /
> the else clause won't be executed in this case...
> please could you examinate this issue and correct it if needed or let me know what is wrong in the precedent discribed comportement/
> /
> Thank's,
> Cyril

Dimitri Papadopoulos
I2BM, NeuroSpin
F-91191 Gif-sur-Yvette cedex, France

More information about the Cubicweb mailing list