-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
fix: json decode #927
fix: json decode #927
Conversation
@asamaayako is attempting to deploy a commit to the sparckles Team on Vercel. A member of the Team first needs to authorize it. |
CodSpeed Performance ReportMerging #927 will not alter performanceComparing Summary
|
Hey! @sansyrox I'm ready to be merged, if you think it's okay。 |
Hey @asamaayako 👋 Reviewing! |
integration_tests/base_routes.py
Outdated
jsondict = request.json() | ||
except ValueError: | ||
jsondict = None | ||
return jsonify(jsondict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just return a dict here. No need to use jsonify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just return a dict here. No need to use jsonify
I try just return dict , but it error, jsondict is not always a dict. it Maybe a list.
when return this value:
jsondict = [{'k': 'v'}, {'k': None}]
it response.body is :
[{'k': 'v'}, {'k': None}]
This is not a valid JSON string.
the valid JSON is that:
[{"k":"v"},{"k":null}]
so , I used jsonify,
src/types/request.rs
Outdated
|
||
dict.set_item(py_key, py_value)?; | ||
} | ||
///serde_json not impl IntoPy<PyObject> but orphan principle. so use this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asamaayako , what is the orphan principle
? Could you please explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asamaayako , what is the
orphan principle
? Could you please explain?
sorry, I means Orphan Rule
. I can't impl IntoPy for serde_json in this create. because either the trait IntoPy or the type serde_json must be defined in the current crate.
src/types/request.rs
Outdated
fn number_to_pyobject(num: serde_json::Number, py: Python) -> PyResult<PyObject> { | ||
match num.as_u64() { | ||
Some(u) => Ok(u.into_py(py)), | ||
None => match num.as_i64() { | ||
Some(i) => Ok(i.into_py(py)), | ||
None => match num.as_f64() { | ||
Some(f) => Ok(f.into_py(py)), | ||
None => Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>( | ||
"Invalid number format", | ||
)), | ||
}, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this handle -1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1
will be python int(-1)
.
It wil handle by num.as_i64() case N::NegInt(n) => Some(n)
, it will into to Python int .
In this function . try parse to uint failed , try parse to int failed , try parse to float ,
f224796
to
b7a3bc8
Compare
Description
This PR fixes #816
Summary
This PR add a function
json_string_to_pyobject
inrequst.rs
. It's converts json_string to Python object.I'm not sure if it's appropriate to put this function in this location.
PR Checklist
Please ensure that:
Pre-Commit Instructions: