namlook / mongokit

MongoKit framework try to keep its simplicity when you manage mongodb in python. MongoKit was developed to be fast and light with KISS and DRY in mind. MongoKit brings structured schema and validation layer on top of the great pymongo driver. Discuss with us on Google group : http://groups.google.com/group/mongokit or follow the news on Twitter: http://twitter.com/namlook
http://namlook.github.com/mongokit/
Other
677 stars 132 forks source link

problem during i18n jsonification #105

Open vied12 opened 12 years ago

vied12 commented 12 years ago

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 ?

namlook commented 12 years ago

Do you have a working test case so I can figure out what is the issue ?

vied12 commented 12 years ago

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

beakid commented 10 years ago

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?