Opened 7 years ago

Closed 7 years ago

Last modified 5 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: UI/UX:

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 Changed 7 years ago by Russell Keith-Magee

milestone: 1.2
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Russell Keith-Magee

Component: UncategorizedCore framework

comment:3 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

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

comment:4 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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