-
Notifications
You must be signed in to change notification settings - Fork 13
fix json emitter for empty response bodies #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can you add a CHANGELOG entry? |
Co-authored-by: bgrant <[email protected]>
) | ||
seria = self.decode(self.construct()) | ||
if isinstance(seria, list): | ||
if len(seria) == 0 or (len(seria) == 1 and len(seria[0]) == 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume in some cases self.decode returns a tuple or something and that's the cause of the clause after the or
? Is there a possibility of guessing this wrong and getting an IndexError on that seria[0]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base case (len == 0) is a just in case. What we actually see with our current issue is [""]
. No, if we have a list of length 1, it would always be accessible and have a length given it's a string (val.decode("utf8")
in self.decode)
@@ -109,6 +109,11 @@ def test_decode(self): | |||
resp = em.render(django.test.RequestFactory().get("/")) | |||
self.assertEqual(json.loads(resp), ["foo", "bar"]) | |||
|
|||
def test_decode_empty_list(self): | |||
em = emitters.JSONEmitter([""], lambda: None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for completeness don't we want another test with a truly empty list?
pyproject.toml
pip install
succeeds with a clean virtualenv