On Sun, Jun 12, 2011 at 11:27 PM, Cal Leeming [Simplicity Media Ltd] <
cal.leem...@simplicitymedialtd.co.uk> wrote:

> I could be wrong, but I'm fairly sure that \xc3\xa3 is a 4 byte unicode
> sequence (which is essentially UTF-16).


No, it's a two-byte sequence -- the UTF-8 encoding of code point
U+00E3, 'LATIN SMALL LETTER A WITH TILDE'.

The original mysql data is probably the latin-1 byte string
'...Famalic\xe3o...'; str.decode('iso-8859-1') converts that into a unicode
string with the U+00E3 code point, and then unicode.encode('utf-8') is
representing that as \xc3\ca3. All correct, up to this point.

It looks like, after this decoding has occurred, and everything is stored,
either the sqlite adapter is returning the wrong data type when retrieving
data from the database, or admin is presenting something unexpected back to
sqlite when saving.

A couple of questions to the original poster might clarify a bit --

1. When do you get this error in admin? When looking at an object list page?
Or looking at an object detail page? Or only when saving objects?

2. Was your custom text_factory used only when you were porting the data
from mysql to sqlite? Or is it still present in your running application?
(And if so, where do you register it?)

3. Are you sure that the data is being stored and retrieved from the
database correctly? What output do you get from the python shell to confirm
that? (It's easy to retrieve wrong data that looks "right enough" when
printed to a terminal). If I was pulling correct data from the database, I
would expect to see something like this:

> from myapp.models import MyModel
> object_from_database = MyModel.objects.get(id=123)
> object_from_database.field_name       # not using "print" here
u'4760 Vila Nova de Famalic\xe3o'

Anything else -- missing the "u", or showing \xc3\xa3 instead of \xe3 here,
would suggest that something is wrong in the database (either stored
incorrectly, or being mis-translated somewhere on retrieval)

4. If you can get the right data out of the database in the python shell,
then can you save it from there as well? If everything above works, then try
doing this:

> object_from_database.save()

and see if you get the same error. If so, posting a traceback from that
might help pinpoint the problem.



-- 
Regards,
Ian Clelland
<clell...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to