django-taggit-serializer
django-taggit-serializer copied to clipboard
'Invalid json list. A tag list submitted in string form must be valid json.
When I try to create object from test client I get this error {'tag': ['Invalid json list. A tag list submitted in string form must be valid json.']}
. Here is the code:
self.client.post('/api/notes/', data={'tag': ["xyz"], 'iv': 'random', 'content': "New content",
'date': self.current_date_time})
Can you try it with:
import json
self.client.post('/api/notes/',
data=json.dumps({
'tag': ["xyz"],
'iv': 'random', 'content': "New content",
'date': self.current_date_time
}))
to check if this "post" only translate the dict
into a str
instead of a valid JSON-String
Here is the response I got after following your suggestion
{'non_field_errors': ['Invalid data. Expected a dictionary, but got str.']}
just to make sure, these are the tests correct?
What about adding the kwarg format
(I just want to make sure format is correct)
self.client.post('/api/notes/', data={'tag': ["xyz"], 'iv': 'random', 'content': "New content",
'date': self.current_date_time}, format='json')
Let me know if that did anything!
I am already using format='json'
.
@pyprism are you able to use it by requesting via HTTP, e.g Postman?
Hi, Same behavior for me with the last (actual) DRF 3.6
{
"tags": [
"Invalid json list. A tag list submitted in string form must be valid json."
]
}
@glemmaPaul It seems like serializer is having trouble with Querydict.
To deal with multiple values for the same key, Querydict stores each value with the same key in a list.
Also, a JSON array treated as a set of values, so its items are stored in a single list.
So, above code will generate Querydict like below:
<QueryDict: {'tag': ['xyz'], 'iv': ['random'], 'content': ['New content'], 'date': [...]}>
And, Querydict returns the last value when accessing for a key.
So, when serializer retrieves the item for a key 'tag', it will get 'xyz', not ['xyz'].
I found the forum article says request.data is sometimes QueryDict, sometimes normal dict. Maybe converting request.data from QueryDict to dict in views.py can temporally solve the problem..
I have the same problem, any solutions?
I'm also having the same problem?
I'm also having the same problem
I ran into the same problem
Was there ever a resolution to this? It is still a prevalent issue with tags in DRF 3.0+ @hsbzzhz @linpan @glemmaPaul
I found a temp solution. I think this is caused by python str is single quote by default but json use double quotes data={'tag': str(["xyz"]).replace("'", '"')} will work
I found a temp solution. I think this is caused by python str is single quote by default but json use double quotes data={'tag': str(["xyz"]).replace("'", '"')} will work
This works for me as well. Thanks! The API itself also seems to work, when called with Postman.
IS there a proper solution now? It worked for me when I gave it as list ["tag1", "tag2]"..
I have the same problem Is there a proposed soltion ? Thanks
I have the same problem Is there a proposed soltion ? Thanks
[ "tag1", "tag2" ]
This worked for me
The same problem here. Any solution?
it's literally one post above, don't send a value but an array of values