Opened 15 years ago

Last modified 13 years ago

#11595 closed Cleanup/optimization

Fixture validation errors should report their data — at Version 5

Reported by: freyley Owned by: Raúl Cumplido
Component: Core (Serialization) Version: 1.0
Severity: Normal Keywords: easy-pickings
Cc: Anand Kumria, Peter van Kampen Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Łukasz Rekucki)

For example, here's what django/db/models/fields/__init__.py has for lines 341-348:

def to_python(self, value):
    if value is None:
        return value
    try:
        return int(value)
    except (TypeError, ValueError):
        raise exceptions.ValidationError(_("This value must be an integer."))

Changing line 348 to:

_("(%s) must be an integer." % value))

means that when you convert a text field to a joined object, you know which one's broken where. (Other places in that file do the same thing)

Change History (5)

comment:1 by Russell Keith-Magee, 15 years ago

Has patch: unset
Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 14 years ago

Description: modified (diff)
Keywords: easy-pickings added
Severity: Normal
Type: Cleanup/optimization

comment:3 by Raúl Cumplido, 14 years ago

Owner: changed from nobody to Raúl Cumplido
Status: newassigned

comment:4 by Raúl Cumplido, 14 years ago

It seems the code is changed since the bug was reported. Now the code has dictionaries with default_error_messages. Example for lines 865-857:

    default_error_messages = {
        'invalid': _("This value must be an integer."),
    }

And in the Exception it has the next, lines 884-890:

    def to_python(self, value):
        if value is None:
            return value
        try: 
            return int(value)
        except (TypeError, ValueError):
            raise exceptions.ValidationError(self.error_messages['invalid'])

Should we change the code to:

    default_error_messages = {
        'invalid': _("(%s) must be an integer."),
    }

    def to_python(self, value):
        if value is None:
            return value
        try: 
            return int(value)
        except (TypeError, ValueError):
            msg = self.error_messages['invalid'] % _(str(value))
            raise exceptions.ValidationError(msg)

I am new and that's why I taked an easy_pickings one. But I want to have your ok to prepare my first patch.

Last edited 14 years ago by Łukasz Rekucki (previous) (diff)

comment:5 by Łukasz Rekucki, 14 years ago

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