-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: ensure Ppydantic models are properly json-ified (#19)
# Context When building props, Pydantic models were converted to dict using Pydantic's `model_dump` method, which converts the model to a dict. When an Inertia call was made, a simple `JSONResponse` (FastAPI's one) was returned, with the props. However, JSONResponse does not handle some fields, such as `datetime`, and would require either: - Handling those prior to passing the models to the `render` method of inertia - Overriding the `render` method of inertia in order to use a custom `JSONResponse` which would handle those cases This is very unoptimal. # Solution - Instead of using Pydantic's `model_dump` method, use its `model_dump_json` method which handles much more types, and use `json.loads` to convert it back to a dict. - Expose a `_render_json` method so it can be easily overridden, without having to override the whole `render` method.
- Loading branch information
Showing
9 changed files
with
489 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Check Package Version | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
- '!main' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-version: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout current branch | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Get version from current branch | ||
id: get_current_version | ||
run: | | ||
current_version=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml) | ||
echo "current_version=$current_version" >> $GITHUB_ENV | ||
- name: Checkout main branch | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: main | ||
path: main_branch | ||
|
||
- name: Get version from main branch | ||
id: get_main_version | ||
run: | | ||
main_version=$(grep -Po '(?<=^version = ")[^"]*' main_branch/pyproject.toml) | ||
echo "main_version=$main_version" >> $GITHUB_ENV | ||
- name: Compare versions | ||
run: | | ||
if [ "$current_version" = "$main_version" ]; then | ||
echo "Version in pyproject.toml is the same as in the main branch." | ||
exit 1 | ||
else | ||
echo "Version in pyproject.toml is different from the main branch." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.