Skip to content

Commit

Permalink
Added error dict to the exception
Browse files Browse the repository at this point in the history
  • Loading branch information
matllubos committed Apr 8, 2021
1 parent d960a5b commit f1bd6c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion chamber/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class PersistenceException(Exception):

def __init__(self, message=None):
def __init__(self, message=None, error_dict=None):
super().__init__()
self.message = message
self.error_dict = error_dict

def __str__(self):
return repr(self.message)
8 changes: 6 additions & 2 deletions chamber/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,12 @@ def _persistence_clean(self, *args, **kwargs):
self.full_clean(exclude=exclude)
except ValidationError as er:
if hasattr(er, 'error_dict'):
raise PersistenceException(', '.join(
('%s: %s' % (key, ', '.join(map(force_text, val))) for key, val in er.message_dict.items())))
raise PersistenceException(
', '.join(
('%s: %s' % (key, ', '.join(map(force_text, val))) for key, val in er.message_dict.items())
),
error_dict=er.message_dict
)
else:
raise PersistenceException(', '.join(map(force_text, er.messages)))

Expand Down
4 changes: 2 additions & 2 deletions example/dj/apps/test_chamber/tests/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ def test_smart_queryset_fast_distinct_shuld_keep_ordering(self):
TestSmartModel.objects.create(name='c')

assert_equal(
TestSmartModel.objects.order_by('name').fast_distinct().values_list('name', flat=True),
list(TestSmartModel.objects.order_by('name').fast_distinct().values_list('name', flat=True)),
['a', 'b', 'c']
)
assert_equal(
TestSmartModel.objects.order_by('-name').fast_distinct().values_list('name', flat=True),
list(TestSmartModel.objects.order_by('-name').fast_distinct().values_list('name', flat=True)),
['c', 'b', 'a']
)

Expand Down
4 changes: 2 additions & 2 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Django==3.1
Django==3.1.6
diff-match-patch==20110725.1
django-germanium==2.1.0
six==1.10.0
coverage==5.3.1
coveralls==2.2.0
pillow==8.0.1
Pillow==8.1.1
boto3==1.16.47
django-storages==1.11.1
-e ../

0 comments on commit f1bd6c2

Please sign in to comment.