Skip to content

Conversation

tdivis
Copy link
Contributor

@tdivis tdivis commented Aug 22, 2018

Reason: some servers send 'error': None.

@coveralls
Copy link

coveralls commented Aug 22, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 6fdcde9 on tdivis:allow-empty-error-field into 124e9f6 on armills:master.

@tdivis
Copy link
Contributor Author

tdivis commented Aug 22, 2018

This was needed to call functions of trac JSON-RPC API.

@emlove
Copy link
Owner

emlove commented Aug 22, 2018

This should really be fixed on the trac side. Per the JSON-RPC Response specifications, the error key must not exist if there is no error.

Alternatively, we could add hooks for downstream libs to register a callback and massage the data before passing it to parse_response to account for non-conforming servers. I imagine it's easiest to just fix the problem at the source though.

@tdivis
Copy link
Contributor Author

tdivis commented Aug 22, 2018

I'm afraid trac uses JSON-RPC 1.0, where specifications says, "error - An Error object if there was an error invoking the method. It must be null if there was no error.".

This pull request allows jsonrpc-base to work with both JSON-RPC 1.0 and 2.0.

@emlove
Copy link
Owner

emlove commented Aug 22, 2018

Ah, I see. I that case, my small preference would be call it out explicitly, instead of relying on it being falsey just to be extra safe. (if data.get('error') is not None:) And we'll need to add an extra test for the JSON-RPC 1.0 format to make sure this isn't accidentally refactored in the future.

It should be sufficient to copy the block below, and test with a response that includes "error": None.
https://github.com/armills/jsonrpc-base/blob/124e9f6ad7d0ae62ea903d639bf4db217b50768d/tests.py#L195-L204

@tdivis tdivis force-pushed the allow-empty-error-field branch from 241cf0e to 6fdcde9 Compare August 22, 2018 14:59
@tdivis
Copy link
Contributor Author

tdivis commented Aug 22, 2018

OK, I did that. Also had to fix tox.ini as there was bug (duplicate testenv:py35 entry).

@emlove emlove merged commit a2f2187 into emlove:master Aug 22, 2018
@emlove
Copy link
Owner

emlove commented Aug 22, 2018

Thanks for the contribution! 🌟

@emlove
Copy link
Owner

emlove commented Aug 22, 2018

I'll get new versions pushed out later today.

@tdivis tdivis deleted the allow-empty-error-field branch August 23, 2018 09:15
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

Successfully merging this pull request may close these issues.

3 participants