Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#13352 closed (fixed)

ValidationError should be able to repr itself

Reported by: elpaso66 Owned by: nobody
Component: Core (Other) Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Actual behaviour:

In [1]: from django.core.exceptions import *

In [2]: ValidationError('Test')
Out[2]: ValidationError()

In [3]: ValidationError(['Test1', 'Test2'])
Out[3]: ValidationError()

Expected behaviour:

In [1]: from django.core.exceptions import *

In [2]: ValidationError('Test')
Out[2]: ValidationError([u'Test'])

In [3]: ValidationError(['Test1', 'Test2'])
Out[3]: ValidationError([u'Test1', u'Test2'])

Patch:

Index: django/core/exceptions.py
===================================================================
--- django/core/exceptions.py   (revision 12889)
+++ django/core/exceptions.py   (working copy)
@@ -64,6 +64,11 @@
             return repr(self.message_dict)
         return repr(self.messages)

+    def __repr__(self):
+        if hasattr(self, 'message_dict'):
+            return 'ValidationError(%s)' % repr(self.message_dict)
+        return 'ValidationError(%s)' % repr(self.messages)
+
     def update_error_dict(self, error_dict):
         if hasattr(self, 'message_dict'):
             if error_dict:

Change History (4)

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

milestone: 1.2
Needs tests: set
Triage Stage: UnreviewedAccepted

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

Component: UncategorizedCore framework

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

Resolution: fixed
Status: newclosed

(In [12976]) Fixed #13352 -- Added repr method for Validation Error. Thanks to elpaso66 for the report.

comment:4 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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