Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:41:20+00:00 2026-06-13T13:41:20+00:00

I come with a really strange Django 1.4 behaviour wich sounds like a bug

  • 0

I come with a really strange Django 1.4 behaviour wich sounds like a bug to me. I looked anywhere if someone experienced it, but didn’t find anything.

My concern is about Django form creation using ModelForm, with a model containing boolean field.

Let Post and Topic two models wich should look like :

class Topic(models.Model):
    my_bool = models.BooleanField(default=False)

class Post(models.Model):
    topic = models.ForeignKey(Topic, related_name='posts')

Now, I’m gonna try to generate a form using TopicForm a class definied elsewhere :

post = Post.objects.get(pk=id_post)
f = TopicForm(instance=post.topic)
print f

It works fine : if in DB my_bool is False, the checkbox is not checked. If my_bool is True, the checkbox is checked. Here is the result :

<p><label for="id_my_bool">my_bool:</label> <input type="checkbox" name="my_bool" id="id_my_bool" /></p>

The problem !

OK, so here is the problem : if I use get_object_or_404 to get my Post object, then my_bool field will always be checked ! Look at this :

post = get_object_or_404(Post.objects.select_related('topic'), pk=id_post)
f = TopicForm(instance=post.topic)
print f

Output (weird) :

<p><label for="id_my_bool">my_bool:</label> <input checked="checked" type="checkbox" name="my_bool" value="0" id="id_my_bool" /></p>

Nota : I tryed several other ways to get the Post object, which all work fine :

  • post = Post.objects.filter(pk=id_post)[0]
  • post = get_object_or_404(Post, pk=id_post)
  • post = Post.objects.get(pk=id_post)

The only thing which makes it bug is :

post = get_object_or_404(Post.objects.select_related('topic'), pk=id_post)

Comments

  • With Django 1.3, there wasn’t any problem with it : only Django 1.4 makes it bug.
  • I found some Django 1.4 bugs which seemed to be related, like :
    • https://code.djangoproject.com/ticket/17747
    • https://code.djangoproject.com/ticket/17114
    • http://groups.google.com/group/django-developers/browse_thread/thread/7d895b2f5fc9ef4b
  • I do not use MySQL GIS backend, but django.db.backends.mysql.

Have you got any idea ?

Thank you very much in advance !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:41:22+00:00Added an answer on June 13, 2026 at 1:41 pm

    Had the same bug in my app and found opened ticket.
    It seems the main problem is in pair select_related & MySQL: MySQL returns integers for booleans but Django can’t associate them with corresponding model when using select_related; consequently, CheckboxInput gets value 0 instead of False and treats it like value in checkbox list.

    You can:

    1. use patch from ticket;
    2. or avoid using select_related;
    3. or patch CheckboxInput widget:

      class SingleCheckboxInput(forms.CheckboxInput):
          def render(self, name, value, attrs=None):
              if value in (0, 1):
                  value = bool(value)
              return super(SingleCheckboxInput, self).render(name, value, attrs)
      
      class TopicForm(django.forms.ModelForm):
          class Meta:
              model = Topic
              widgets = {'my_bool': SingleCheckboxInput}
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really like parser combinators but I'm not happy with the solution I've come
Come across what looks at first sight like an MT-issue, but I'm trying to
I've come across a really strange problem. I have written a simple Deck class
I've come across a really strange situation (to me at least) while writing some
I've searched for this question but I only come across really specific answers that
I've had a look through existing questions, but I haven't really come across anything
I'm trying to find a really strange bug in my application and while looking
I have come to know that from IE 5, there is a strange behaviour
I couldn't really come up with a proper title for my question but allow
I've tried Goggling this, but I can't really come up with a technical string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.