Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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:

Attachments (0)

Change History (4)

comment:1 Changed 4 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by russellm

  • Component changed from Uncategorized to Core framework

comment:3 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:4 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.