-
-
Notifications
You must be signed in to change notification settings - Fork 7k
MultiPart encoding from test client should error on nested data. #2919
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
MultiPart encoding from test client should error on nested data. #2919
Conversation
|
@j0hnsmith Looks like a nice simple test to me. Thanks for linking me in. |
|
Ok having a dig at this. Could either of you give some more context about how/when are you folks encountering this? |
|
Yes, I'm seeing this in tests however I've realised my test wasn't setting So this probably down to people accidentally sending json data as |
|
@j0hnsmith |
|
@xordoquy thanks for the heads up. I get confused between the apis of requests, the django test client and drf test client. As per the drf testing docs I've modified my test to |
|
Fails due to serializers using the We could change it so that the test doesn't fail, but actually it's not really a valid case. A better solution might be to ensure that multipart encoded test client requests raise an error, like "what the flip are you trying to do there, kiddo. Nope, you can't - HTML Form input doesn't support that" |
|
"actually it's not really a valid case", agreed. A warning would be useful. |
|
@j0hnsmith Sounds like a good plan - retitling this issue. We should raise an error when this is used in the test client, like "MultiPart form content cannot support nested dictionaries. Consider using format="json" instead." Possibly related - we could consider raising a similar error if a file object is passed to JSON in the test client, like "JSON cannot support file uploads. Consider using format="multipart" instead." |
|
@j0hnsmith I just removed some suspicious messages coming from you. |
|
@xordoquy thanks, my email got hacked. |
When I run the tests the failure complains about unbalanced braces, however here's a demonstration of the problem (using 3.1.1 from pypi)
The same test with a normal dict passes.
I'm pretty sure this is a stripped back demonstration of the problem discussed in #1936. As suggested by @jamescooke in (#1936 (comment)), it seems like the
QueryDictshould be handled here https://github.com/tomchristie/django-rest-framework/blob/35efbe41abcff15ea2f60096aaa95bd41f2532a3/rest_framework/serializers.py#L350-356