> So values that are
> ultimately coming from the database (as when you do a get) are returned from
> MySQL as 1/0 while values that originate from Python code are true bools and
> get reported as True/False.

Yes, you've explained it well.

My code in the ReST client expects 1/0 so True/False is giving me
trouble, but I'm inspecting the xml and replacing True with 1 and
False with 0.

I was just looking for an explanation for this behavior.

Thanks.

On Mar 23, 7:16 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Mar 23, 2009 at 9:47 AM, chefsmart <moran.cors...@gmail.com> wrote:
>
> > I have not changed my database. I've always been using MySQL.
>
> > In the meantime I did some more research and discovered that when I
> > use HTTP GET on a model (I'm talking django-rest-interface) the xml
> > returned has 1 or 0 for Boolean values, which is what I want.
>
> > However, when I do an HTTP PUT to update an instance of a model, the
> > xml response has True or False for Boolean values.
>
> > Though I'm using django-rest-interface, the de/serialization is
> > handled by Django itself.
>
> > I have tried walking through the code to find out what is going on,
> > but no luck yet.
>
> I'm not familiar with django-rest, but what you are describing doesn't
> surprise me.  I think it's a consequence of Django not coercing boolean
> field values coming from MySQL to an actual bool value.  So values that are
> ultimately coming from the database (as when you do a get) are returned from
> MySQL as 1/0 while values that originate from Python code are true bools and
> get reported as True/False.  Heading towards MySQL this is fine, as MySQL
> will accept True/False and internally transform them to the 1/0 it wants to
> use, but heading in the other direction the 1/0 returned by MySQL can
> sometimes lead to confusion in other code that is expecting true bool, not
> int, values.
>
> There was a ticket requesting that the 1/0 returned by MySQL be cast to a
> bool:
>
> http://code.djangoproject.com/ticket/7190
>
> but that got closed wontfix and some doc was added to note that MySQL
> behaves this way.   It isn't clear from what you've posted if the
> inconsistency is causing a problem for you or if you just noticed it and it
> concerned you?
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
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