couchdb-python
couchdb-python copied to clipboard
Proper handling mapping.DictField default values
From daevaorn on June 06, 2011 13:31:08
DictField
accepts default value and has default default as empty dict. But if mapping
parameter is specified user is expecting empty Mapping
instance as default value not empty dict. Or if default is already Mapping
instance so it doesn't have copy()
method and that causes an error.
Patch is attached.
Attachment: dictfield_default.diff
Original issue: http://code.google.com/p/couchdb-python/issues/detail?id=185
From kxepal on June 08, 2011 09:28:48
I understand idea of this patch, but it doesn't solves issue: class Image(Mapping): name = TextField() url = TextField()
class Post(Mapping): title = TextField() logo = DictField(Image, default={'name': 'post logo'}) attached_image = DictField(Mapping.build( name=TextField(), url=TextField() ), default=Image(name='attached image'))
post = Post(title='test post') # TypeError: MappingMeta object argument after ** must be a mapping, not Image
I suppose that better to implement full dict API to Mapping instance because it represented ORM to dict object instead of trying to do same thing within Field instances.