Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

adding example usage (REST payloads) to the readme would be very helpful #16

Closed
honestbleeps opened this issue Sep 15, 2015 · 4 comments
Assignees

Comments

@honestbleeps
Copy link

First and foremost: thanks for creating this, your work is appreciated!

I am unfortunately unable to get it working. I've got the GET request for my model returning tags: [] as expected, but when I call a PATCH method and submit the data as either strings, a string representation of an array, etc, it doesn't seem to work.

Because there isn't documentation on what my payload should look like, I've just tried everything I can think of, and it always comes back with an empty tag list, which makes it hard to know if I've configured something wrong or I'm sending the wrong payload. I've tried the following values for "tags" in my PATCH request:

foo
foo bar
["foo", "bar"]
["foo"]

so far, nothing gets created in the database, no error is thrown, etc, so it's unclear what I might be doing wrong.

I'd be happy to contribute back some examples if/when I get it working, but right now I'm a bit stymied!

@honestbleeps
Copy link
Author

I've ended up getting my requests working, but I still haven't figured out what the payload is supposed to look like to remove tags from a model.

@honestbleeps honestbleeps changed the title adding example usage to the readme would be very helpful adding example usage (REST payloads) to the readme would be very helpful Sep 15, 2015
@glemmaPaul
Copy link
Owner

@honestbleeps Thanks for creating this issue. I've never thought about this. So are you saying that you also get no sufficient feedback when doing it wrong?

@glemmaPaul glemmaPaul self-assigned this Sep 16, 2015
@honestbleeps
Copy link
Author

Yeah, it may ultimately be a problem laying inside of Django Rest Framework and/or the tool I was using to test, Postman (a chrome extension). I was trying to send something like:

key: tags
value: ["1", "2", "3"]

and that didn't work, so then I figured I'd try:

key: tags[]
value: "1"

key: tags[]
value: "2"

and that didn't work either... finally I realized you have to actually put array index numbers on Postman to send. There's no real way for django-taggit-serializer to give good error messages here because it's not receiving "malformed" data, it's stripped down to nothing by the time your code sees it.

I did maybe find a bug, though. I haven't been able to create a reduced test case, but once I got things working, I found that it wasn't overwriting the "tags" array, but rather adding any new tags that didn't exist to it and not removing them.

It appears from your tests that if I patch MyModel with something like:

{ "tags": ["a", "b"] }

and it already has one tag, let's say "c", the end result should still be:

{ "tags": ["a", "b"] }

However, when I ran a PATCH request using Postman, with fields as follows:

tags[0]: "a"
tags[1]: "b"

I would end up with tags "a", "b" and "c" all on my model. I'm not sure why, and I am unable to stop what I'm working on at the moment to create a reduced test case.

I will close this issue as I don't think it's one you can really respond to if django-rest-framework doesn't send you any actionable data (it empties out "tags" rather than passing on anything malformed). However, you might try updating your tests to do actual http requests rather than serializer.save calls to see if the bug I found is within your own code or maybe it's something odd I have in my own installation of django-rest-framework (but I wasn't doing a custom override of the PATCH method, so I wouldn't think my own code would be the issue)

@glemmaPaul
Copy link
Owner

@honestbleeps Yes you are right, Forms don't go well with lists. When you would use JSON you could do the following:

{
  "tags": ["tag1", "tag2"]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants