#29618: using query parameters to filter by boolean causes validation error due 
to
lowercase true/false
-------------------------------------+-------------------------------------
     Reporter:  levi schubert        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  2.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  filter               |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

 Ah, it it does take `'False'` — my mistake. (That explains using
 `title()`.) This shouldn't work IMO. (But I suppose we can't change that
 for BC reasons...?)

 For reference:

 * Django `forms`: See
 
[https://github.com/django/django/blob/49f97b645fb1716cf69177558c41cf650a701eed/django/forms/fields.py#L701
 `forms.BooleanField.to_python()`], with e.g.
 
[https://github.com/django/django/blob/49f97b645fb1716cf69177558c41cf650a701eed/django/forms/widgets.py#L518
 `CheckboxInput.value_from_datadict()`]. The widget pulls the value from
 the `GET` `QueryDict`, which is then passed to the field, before being
 accessed via the form's `cleaned_data`.
 * Django REST Framework serialisers: See [https://github.com/encode
 /django-rest-
 
framework/blob/8493990a66e36d5dd4a62742d861b5b6b15cae80/rest_framework/fields.py#L682
 `BooleanField.to_internal_value()`]. The mapping from the various input
 values to a bool is done in a single step, being made available by the
 serialiser's `validated_data`.

 Either way, the input is sanitised and correctly cast to the boolean type
 before ever encountering the model field.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29618#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.c147bbdb2321855d8e44766a0e3e33bb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to