I'm facing a weird issue, possibly a bug (python SDK), while
subclassing a TextProperty or BlobProperty in order to make a
JSONProperty. I read pretty much anything on python/unicode/utf-8/
encoding/decoding I could find via Stackoverflow, Python.org, Google
or this group, including Nick Johnson's guide to getting unicode
right : http://blog.notdot.net/2010/07/Getting-unicode-right-in-Python.

Here's my custom property code :

class JSONProperty(db.TextProperty):
    def get_value_for_datastore(self, model_instance):
        result = super(JSONProperty,
self).get_value_for_datastore(model_instance)
        result = simplejson.dumps(result, ensure_ascii = False)
        return self.data_type(result)

    def make_value_from_datastore(self, value):
        result = simplejson.loads(value)
        return result

Values are set this way prior in my code :

some_dict['some_key'] = u"Hello çéàôùî world !"

Each value within the dict is then converted to unicode this way :
unicode(v, 'utf-8')

All files use the following header : # This Python file uses the
following encoding: utf-8

The code works perfectly on dev : the JSON string is inserted in the
datastore, and non-ASCII characters are perfectly visible within the
JSON string as expected when viewing it within the datastore viewer
(like ç, é, à, û, etc.).

I get a UnicodeDecodeError on prod every time when trying to put() a
model instance in the datastore. End of stack trace :

  File "/base/python_runtime/python_lib/versions/1/google/appengine/
api/datastore_types.py", line 1485, in PackString
    pbvalue.set_stringvalue(unicode(value).encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
32: ordinal not in range(128)

Regards,

-jbmusso

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to