lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

Proper handling mapping.DictField default values #185

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
`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.

Original issue reported on code.google.com by daevaorn on 6 Jun 2011 at 11:31

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by kxepal on 8 Jun 2011 at 4:28

GoogleCodeExporter commented 8 years ago
This issue has been migrated to GitHub. Please continue discussion here:

https://github.com/djc/couchdb-python/issues/185

Original comment by djc.ochtman on 15 Jul 2014 at 7:21