Skip to content

Commit

Permalink
Merge pull request #83 from ghazi-git/show-exceptions-with-empty-detail
Browse files Browse the repository at this point in the history
show-exceptions-with-empty-detail
  • Loading branch information
ghazi-git authored Aug 10, 2024
2 parents d378178 + faed309 commit 40bb615
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [UNRELEASED]
### Fixed
- stop ignoring exceptions with detail as an empty string when returning api errors.

## [0.14.0] - 2024-06-19
### Added
Expand Down
2 changes: 1 addition & 1 deletion drf_standardized_errors/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def flatten_errors(
errors = []
while fifo:
detail, attr, index = fifo.pop(0)
if not detail:
if not detail and detail != "":
continue
elif isinstance(detail, list):
for item in detail:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_flatten_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ def test_does_not_raise_recursion_error():
"Failed due to a recursion error. Use an iterative approach rather than "
"a recursive one to avoid reaching the maximum recursion depth in python."
)


def test_exception_with_detail_empty():
detail = {"some_field": [ErrorDetail("", code="invalid")]}
errors = flatten_errors(detail)
assert len(errors) == 1
assert errors[0].attr == "some_field"
assert errors[0].detail == ""

0 comments on commit 40bb615

Please sign in to comment.