Opened 9 years ago

Last modified 9 years ago

#26131 closed Bug

model field choices are not enforced — at Version 3

Reported by: stiffupperlip Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by stiffupperlip)

In Django 1.8.8 when I create a model class like below, choices are not enforced when creating an instance of the model class:

class HTTPMethod(models.Model):
    HTTP_METHODS = [(_, _) for _ in ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace', 'connect']]

    id = models.AutoField(primary_key=True)
    name = models.CharField(choices=HTTP_METHODS, unique=True, max_length=255)


h = HTTPMethod(name='something invalid')
h.save()

No errors are raised and invalid data is stored in the model.

Python 2.7.6 on Ubuntu 14.04

Change History (3)

comment:1 by stiffupperlip, 9 years ago

Description: modified (diff)

comment:2 by stiffupperlip, 9 years ago

Description: modified (diff)

comment:3 by stiffupperlip, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top