mongokit
mongokit copied to clipboard
problem during i18n jsonification
When I try :
json.dumps([_.to_json_type() for _ in news])
news is a cursor, I have this error:
File "/home/edouard/.local/lib/python2.7/site-packages/mongokit/document.py", line 479, in to_json_type
self._process_custom_type('bson', self, self.structure)
File "/home/edouard/.local/lib/python2.7/site-packages/mongokit/schema_document.py", line 652, in _process_custom_type
new_path, struct[key].python_type.__name__, type(doc[key]).__name__))
File "/home/edouard/.local/lib/python2.7/site-packages/mongokit/schema_document.py", line 524, in _raise_exception
raise exception(message)
SchemaTypeError: content must be an instance of i18n not list
Do you have any idea of what happens ?
Do you have a working test case so I can figure out what is the issue ?
Maybe I upgrade pymongo or mongokit, but the following code doesn'ty work anymore with the latest versions
#!/usr/bin/env python
# Encoding: utf-8
import mongokit, datetime
connection = mongokit.Connection()
@connection.register
class News(mongokit.Document):
__collection__ = 'news'
__database__ = 'test'
structure = {
'title' : unicode,
}
i18n = ['title']
use_dot_notation = True
if __name__ == "__main__":
connection.test.news.remove()
news = connection.News()
news.title = u"[en] pouet"
news.set_lang("fr")
news.title = u"[fr] pouet"
news.save()
all_news = connection.test.news.find()
print list(all_news)
I have
Traceback (most recent call last):
File "testCase.py", line 20, in <module>
news.title = u"[en] pouet"
File "/home/edouard/.local/lib/python2.7/site-packages/mongokit/schema_document.py", line 362, in __setattr__
self[key][self._current_lang] = value
TypeError: 'NoneType' object does not support item assignment
It works with mongokit 0.7.2
and pymongo 2.0.1
I'm also getting this error ( "self[key][self._current_lang] = value" ), but can't find the 0.7.2 version of mongokit anymore so I can't verify if it's working with that version.
@vied12 : Did you solve this issue?