0

For some reason I have a boolean field in a Store model that has stopped updating. I have a frontend application (ember.js) and a Django Rest Framework backend.

I first thought the problem was in my ember application even though in the request it was sending the open field correctly. I then noticed that in the browsable DRF API it was also ignoring the open field so there is definitely something wrong on the Django side of things.

# models.py
class Store(models.Model):
    """
    Single vendor of coffee. The user will be able to access the store and
    manage their drinks and information.
    """
    user = models.OneToOneField(User)
    name = models.CharField(max_length=30)
    open = models.BooleanField(default=False)
    confirm_message = models.CharField(max_length=500)

# serializers.py
class StoreSerializer(ModelSerializer):
    class Meta:
        model = Store

# views.py
class StoreViewSet(ModelViewSet):
    queryset = Store.objects.all()
    serializer_class = StoreSerializer

Everything seems pretty cookie-cutter but for some reason the BooleanField is being ignored. All the other fields are updating correctly.

Any ideas what it might be?

M.javid
  • 6,387
  • 3
  • 41
  • 56
awwester
  • 9,623
  • 13
  • 45
  • 72
  • `open` is function in python. function cannot be used as variable names. – Seenu S Sep 10 '15 at 20:25
  • Your code is working fine. I'm able to update the `opened=True`. – Seenu S Sep 10 '15 at 20:31
  • Sorry, should have mentioned that. I saw that as well and have tried changing the field name but it didn't change. Other boolean fields (named 'active') in other models are doing the same thing – awwester Sep 10 '15 at 21:30
  • Everything was working before, but something happened that makes the boolean fields non-responsive. – awwester Sep 10 '15 at 21:31
  • Everything is working for me. I'm able to update the Store object. Check something else be the problem. – Seenu S Sep 10 '15 at 21:37
  • Take a look at [this answer](http://stackoverflow.com/a/11922878/20712) to print out the SQL being sent to your database. Then you can determine whether someone changed the DB outside of Django or whether it is the code path before the commands are sent to the server. – Ross Rogers Sep 11 '15 at 13:36
  • @RossRogers Thanks that helped see that the problem is before the DB Query gets generated – awwester Sep 16 '15 at 19:19

1 Answers1

0

Not sure what was the cause of the problem, but upgrading from DRF 3.1.x to 3.2.x fixed the issue. Something was broken before the DB Query was generated and it wasn't sending the right value for Boolean Fields.

awwester
  • 9,623
  • 13
  • 45
  • 72