Skip to content
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

files: DeleteV2 method isn't working #22

Closed
ncw opened this issue Aug 8, 2017 · 5 comments
Closed

files: DeleteV2 method isn't working #22

ncw opened this issue Aug 8, 2017 · 5 comments
Assignees

Comments

@ncw
Copy link
Contributor

ncw commented Aug 8, 2017

When I tried the DeleteV2 method I get this error

json: cannot unmarshal object into Go struct field DeleteResult.metadata of type files.IsMetadata

The HTTP transaction looks like this

request

2017/08/08 10:37:41 DEBUG : HTTP REQUEST (req 0xc4201e0700)
2017/08/08 10:37:41 DEBUG : POST /2/files/delete_v2 HTTP/1.1
Host: api.dropboxapi.com
User-Agent: rclone/v1.37-DEV
Content-Length: 48
Authorization: XXXX
Content-Type: application/json
Accept-Encoding: gzip

{"path":"/rclone-test-nuhexes9qaroxer3desayuz2"}

response

2017/08/08 10:37:42 DEBUG : HTTP RESPONSE (req 0xc4201e0700)
2017/08/08 10:37:42 DEBUG : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Date: Tue, 08 Aug 2017 09:37:42 GMT
Pragma: no-cache
Server: nginx
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Dropbox-Request-Id: 9d6eb7365903bb2a425e751778a4c887
X-Frame-Options: SAMEORIGIN
X-Server-Response-Time: 628

e3
{"metadata": {".tag": "folder", "name": "rclone-test-nuhexes9qaroxer3desayuz2", "path_lower": "/rclone-test-nuhexes9qaroxer3desayuz2", "path_display": "/rclone-test-nuhexes9qaroxer3desayuz2", "id": "id:qqS0afUHwS0AAAAAAABZ2g"}}
0

The verbose logging from the SDK looks like this

2017/08/08 10:41:09 arg: &{/rclone-test-gosocik0bewamen9sufotef3}
2017/08/08 10:41:09 req: &{POST https://api.dropboxapi.com/2/files/delete_v2 HTTP/1.1 1 1 map[Content-Type:[application/json]] {0xc420195ef0} 0x670830 48 [] false api.dropboxapi.com map[] map[] <nil> map[]   <nil> <nil> <nil> <nil>}
2017/08/08 10:41:10 resp: &{200 OK 200 HTTP/1.1 1 1 map[Date:[Tue, 08 Aug 2017 09:41:10 GMT] Pragma:[no-cache] Content-Type:[application/json] X-Frame-Options:[SAMEORIGIN] X-Server-Response-Time:[643] Vary:[Accept-Encoding] Cache-Control:[no-cache] X-Dropbox-Request-Id:[de7731f3a5db4d54dec94067c74b644c] Server:[nginx] Connection:[keep-alive] X-Content-Type-Options:[nosniff]] 0xc42022dce0 -1 [chunked] false true map[] 0xc4201bce00 0xc42023c840}
2017/08/08 10:41:10 body: [123 34 109 101 116 97 100 97 116 97 34 58 32 123 34 46 116 97 103 34 58 32 34 102 111 108 100 101 114 34 44 32 34 110 97 109 101 34 58 32 34 114 99 108 111 110 101 45 116 101 115 116 45 103 111 115 111 99 105 107 48 98 101 119 97 109 101 110 57 115 117 102 111 116 101 102 51 34 44 32 34 112 97 116 104 95 108 111 119 101 114 34 58 32 34 47 114 99 108 111 110 101 45 116 101 115 116 45 103 111 115 111 99 105 107 48 98 101 119 97 109 101 110 57 115 117 102 111 116 101 102 51 34 44 32 34 112 97 116 104 95 100 105 115 112 108 97 121 34 58 32 34 47 114 99 108 111 110 101 45 116 101 115 116 45 103 111 115 111 99 105 107 48 98 101 119 97 109 101 110 57 115 117 102 111 116 101 102 51 34 44 32 34 105 100 34 58 32 34 105 100 58 113 113 83 48 97 102 85 72 119 83 48 65 65 65 65 65 65 65 66 90 54 81 34 125 125]
@ncw
Copy link
Contributor Author

ncw commented Aug 9, 2017

Looking at the code I see DeleteResult is defined thus

// DeleteResult : has no documentation (yet)
type DeleteResult struct {
	FileOpsResult
	// Metadata : Metadata of the deleted object.
	Metadata IsMetadata `json:"metadata"`
}

IsMetadata is defined thus

// IsMetadata is the interface type for Metadata and its subtypes
type IsMetadata interface {
	IsMetadata()
}

I don't think it is possible to unmarshal into an interface type. Here is an example modified from the json docs.

This probably needs to be done differently with a json.RawMessage and calling IsMetadataFromJSON

@diwakergupta
Copy link
Collaborator

@ncw hmm, the generator probably needs to be tweaked. I'll take a look later today. And yep, as you noted, IsMetadataFromJSON exists precisely because we can't unmarshal onto an interface type :) As an example of how the SDK already does this for Union types, check out metadataUnion and the associated UnmarshalJSON method.

@diwakergupta diwakergupta self-assigned this Aug 9, 2017
@diwakergupta
Copy link
Collaborator

Alright, I know the problem. I might push a hacky fix first, and generalize later. Are you blocked on this @ncw ?

@ncw
Copy link
Contributor Author

ncw commented Aug 9, 2017

I can't update the library as the depreciation warnings make too much noise in my logs without changing the Delete to DeleteV2.

I have a vendored working copy though so take your time!

I noticed in my investigations that IsMetadataFromJSON isn't being called at all at the moment.

@ncw
Copy link
Contributor Author

ncw commented Aug 11, 2017

I can confirm that this works fine now - thanks :-)

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

No branches or pull requests

2 participants