Opened 4 years ago

Closed 4 years ago

#32530 closed Bug (duplicate)

readonly makes field return None on cleaned_data?

Reported by: Ricky Manalo Owned by: nobody
Component: Forms Version: 3.1
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

On my Form's clean(), I'm getting the values of some fields from their cleaned_data and check if they are empty and throw a ValidationError when they are. When certain conditions are met, all the fields would be readonly when editing. Initial saving works fine. But when I try to resave a Form which the fields I needed to check are readonly, somehow it creates a ValueError: 'Form' has no field named 'field_name', making me think that when a field is readonly, it's value isn't being set on it's cleaned_data or the Form "forgets" it's model's fields.

def clean(self):
        start_date = self.cleaned_data.get('start_date')
        end_date = self.cleaned_data.get('end_date')

        if start_date is None:
            raise forms.ValidationError({'start_date': ["Start date is empty",]})
        elif end_date is None:
            raise forms.ValidationError({'end_date': ["End date is empty",]})

The ValueError is thrown by the if start_date is None: line

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #30373, see comment.

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