Comments (6)
Dear @cjerdonek
I have some concerns about that use case. As you mentioned, application might raise an exception, which is not under developer's control. If library would not validate the type, it might affect frontend developers later on. My suggestion would be to inherit from current serializer and inject it to jsonrpc manager.
from jsonrpc.utils import DatetimeDecimalEncoder
class MyEncoder(DatetimeDecimalEncoder):
def default(self, o):
try:
return super(MyEncoder, self).default(self, o)
except TypeError:
return repr(o)
Then this encoder could be used here: https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/backend/django.py#L62
Please let me know if that works.
from json-rpc.
@pavlov99 Thanks for such a prompt reply. It seems to me though that json-rpc has a responsibility to meet its guarantee and return valid JSON. Every application is susceptible to this issue. (Incidentally, it also seems that the issue isn't limited to the Django backend as you will see below.)
In this function, JSONRPCResponseManager
constructs a JSONRPCServerError
when an exception occurs. However, it makes the assumption that e.args
is JSON serializable, which isn't necessarily the case. It seems json-rpc shouldn't be creating a JSONRPCError
object there if it can't guarantee that the object is actually serializable.
from json-rpc.
Another suggestion: if you are concerned about backwards-forwards compatibility, etc, how about handling the serialization exception and raising a serializable exception saying something like, "unserializable error raised with type: ..."? That way developers will at least be alerted to the issue on a case-by-case basis, but as JSON as opposed to 500 response.
from json-rpc.
For the record, I just want to include this from the JSON-RPC 2.0 Specification, section 5 Response object:
When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response is expressed as a single JSON Object, with the following members:
Thus, this issue is about a case in which json-rpc does not respond with a JSON object. Json-rpc should have some kind of global exception handler to ensure that it always returns a JSON response, regardless of the underlying application code.
from json-rpc.
@cjerdonek absolutely agree with the latest point. Let me add tests for Django 1.9.
from json-rpc.
I am facing the same problem. Any news on this?
from json-rpc.
Related Issues (20)
- Consider switching to CircleCI HOT 1
- pip install json-rpc breaks pyls installation HOT 3
- Django documentation params HOT 8
- json-rpc 1.0 requires 'result' and 'error' attributes in the HTTP responses
- Cors Header Missing ? HOT 1
- Feature proposal: Remote Method Invocation dispatcher HOT 1
- Can't an AsyncJSONRPCResponseManager be added? HOT 4
- Need a way to intercept exception to send http 401
- Unreachable OpenRPC rpc.discover method HOT 1
- ĺ źĺŽš django 4.0 HOT 2
- JSONRPCResponseManager.handle silences the exception if "id" is not passed
- Missing git tags for 1.14.0 and 1.15.0 releases
- Add names for django's views HOT 3
- License file in pypi archive HOT 5
- Link to implementations on project page is useless
- Uart as a transport layer HOT 1
- Server issued notifications HOT 2
- Using SELF in class methods when using JSON-RPC as a class HOT 2
- `make env` fails without requirements-dev.txt HOT 1
- How to deploy on production server? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-rpc.