Hello there,
I have been doing some work with the API and I have found the
following problem:
Currently I have my objects that returns a dictionary(get_object_data
method) in order to easily serialize it in to a JSON object. This work
perfectly when creating a new doc. The problem I found is when I want
to update a doc in the database doing the following:
# add object
person.id = db.create(person.get_object_data())
person.name = "test"
doc = db[
person.id]
# I get all the data because although in the example I just changed
name, thee are cases where more is changed.
doc = person.get_object_data()
Bare in mind that the dict returned bey )get)object_data is usually
like this:
{
'surname': 'de la Pena',
'addresses': [
{
'city': 'Brussels',
'country': 'Belgium',
'state': 'Brussels',
'street': 'Rue du Prevot',
'postcode': '1050',
'address_type': 'Work',
'type': 'Address',
'location': 'Local'
}, {
'city': 'Madrid',
'country': 'Spain',
'state': 'Madrid',
'street': 'C/Caracas 19 6 drch',
'postcode': '28010',
'address_type': 'Work',
'type': 'Address',
'location': 'Local'}],
'social_accounts': [],
'middleName': '',
'title': 'Mr.',
'comments': '',
'id': u'49e43cf1bb70d65f7235c1ee1809d707',
'webs': [],
'ims': [],
'preferred_address':
{
'city': 'Madrid',
'country': 'Spain',
'state': 'Madrid',
'street': 'C/Caracas 19 6 drch',
'postcode': '28010',
'address_type': 'Work',
'type': 'Address',
'location': 'Local'
},
'numbers': [
{
'regional_code': '',
'international_code': '',
'type': 'TelephoneNumber',
'number': '22333',
'number_type': 'Work'
},
{
'regional_code': '',
'international_code': '',
'type': 'TelephoneNumber',
'number': '9231933',
'number_type':
'Work'
}],
'printMode': 0,
'logo': '',
'type': 'Person',
'emails': [
{
'email_type': 'Home',
'type': 'EmailAddress',
'email': '
eti...@gmail.com',
'format': 'Internet'
},
{
'email_type': 'Home',
'type': 'EmailAddress',
'email': '
man...@themacaque.com',
'format': 'Internet'
}],
'name': 'Manuel'
}
When executing the above code I get the following exception:
File "/var/lib/python-support/python2.6/couchdb/client.py", line 527,
in update
raise TypeError('expected dict, got %s' % type(doc))
TypeError: expected dict, got <type 'str'>
Which I find very odd,
can anyone give me a hand with this.
Kr,
Mandel