Friday, September 19, 2014

Possible Bug - PositiveSmallIntegerField Enables Saving Negative Values

from django.db import models

# Create your models here.

class Snapple(models.Model):

x = models.PositiveSmallIntegerField()
I have generated a very simple test project using a fresh copy Django 1.7.0 with a model that has a PositiveSmallIntegerField, it is attached to this post. The ORM is not preventing instances being created with that field's value set to -1

>>> django.VERSION

(1, 7, 0, 'final', 0)

$ python manage.py shell

Python 2.7.8 (default, Aug 24 2014, 21:26:19) 

[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

(InteractiveConsole)

>>> from snapple.models import Snapple

>>> x = Snapple.objects.create(x=-1)  # x ought to be a PositiveSmallIntegerField

>>> x.x

-1

>>> 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/569c70c9-b283-4e89-9f46-ed8fc397798b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment