Opened 4 years ago

Closed 4 years ago

#31049 closed Bug (duplicate)

BooleanField error.

Reported by: Shinneider Libanio da Silva Owned by: nobody
Component: Forms Version: 2.2
Severity: Normal Keywords: forms, booleanfield
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Shinneider Libanio da Silva)

Hi.

i want to try use a BooleanField for validate my received boolean values

forms.BooleanField().validate(value=False)

but a error occurs. searching in the BooleanField code, and i see this:

  def validate(self, value):
        if not value and self.required:
            raise ValidationError(self.error_messages['required'], code='required')

however 'False' is a valid value for a BooleanField, but is blocked by if, the correct would be:

  def validate(self, value):
-       if not value and self.required:
+       if value is None and self.required:
            raise ValidationError(self.error_messages['required'], code='required')

can i open a PR for this ?

Change History (3)

comment:1 by Shinneider Libanio da Silva, 4 years ago

Description: modified (diff)

comment:2 by shubham singh , 4 years ago

Found this while going through the documentation, it seems that the validate() method for BooleanField is working as expected, you can read more about it in the documentation .
Furthermore, a similar issue has also been reported in the past ticket:23547#comment:5.

comment:3 by Mariusz Felisiak, 4 years ago

Resolution: duplicate
Status: newclosed
Summary: BooleanField errorBooleanField error.

Duplicate of #23547. This is a documented behavior.

Note: See TracTickets for help on using tickets.
Back to Top