Skip to content

Commit 40bb615

Browse files
authored
Merge pull request #83 from ghazi-git/show-exceptions-with-empty-detail
show-exceptions-with-empty-detail
2 parents d378178 + faed309 commit 40bb615

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

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

911
## [0.14.0] - 2024-06-19
1012
### Added

drf_standardized_errors/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def flatten_errors(
109109
errors = []
110110
while fifo:
111111
detail, attr, index = fifo.pop(0)
112-
if not detail:
112+
if not detail and detail != "":
113113
continue
114114
elif isinstance(detail, list):
115115
for item in detail:

tests/test_flatten_errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ def test_does_not_raise_recursion_error():
118118
"Failed due to a recursion error. Use an iterative approach rather than "
119119
"a recursive one to avoid reaching the maximum recursion depth in python."
120120
)
121+
122+
123+
def test_exception_with_detail_empty():
124+
detail = {"some_field": [ErrorDetail("", code="invalid")]}
125+
errors = flatten_errors(detail)
126+
assert len(errors) == 1
127+
assert errors[0].attr == "some_field"
128+
assert errors[0].detail == ""

0 commit comments

Comments
 (0)