>>> When using a PickleCol with default={ } the behaviour is not exactly
>>> what I would expect:
>>>
>>> ######################################################################
>>> from sqlobject import *
>>> sqlhub.processConnection = connectionForURI( 'sqlite:///:memory:',
>>> debug=True )
>>> class t( SQLObject ):
>>> x = PickleCol( default={} )
>>> t.createTable( )
>>> row = t( )
>>> print row.x # this will print None
>>> ######################################################################
>>>
>>> Having a non-empty dict works as expected though. I had a feeling it
>>> was related to mutable keyword argument values and the associated
>>> problems, but the same problem is there with an empty tuple which is
>>> certainly unmutable.
>>>
>>> Is this a bug or a feature?
>>
>> Seems like a bug related to boolean testing of objects. I.e.,
>> somewhere
>> there is a code that does
>>
>> if object:...
>>
>> instead of
>>
>> if object is None:...
>>
>> But a quick glance at PickleCol code didn't reveal a clue.
>
> I thought the same first, but StringCol( default='' ) works as
> expected, although the empty string also evaluates to False as
> boolean. And I'd think this part of the code (testing for default) is
> the same for every col type. So I'm sufficiently confused, I'll keep
> looking at the code.
I've investigated this further and the problem is with the validator
PickleCol wants to use.
If I insert a 'print kw' before and after
line 1066: kw[name] = dbValue = from_python(value, self._SO_validatorState)
in main.py and do the following:
######################################################################
from sqlobject import *
sqlhub.processConnection = connectionForURI( 'sqlite:///:memory:' )
class t( SQLObject ):
x = PickleCol( default={} )
t.createTable( )
row = t( )
######################################################################
I'll get:
{'x': {}}
{'x': None}
I.e. the empty dict here gets validated to None. But I couldn't find
out the reason for this, PickleCol uses a complicated validator.
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss