Skip to content

Conversation

@Druid-of-Luhn
Copy link
Contributor

@Druid-of-Luhn Druid-of-Luhn commented Jan 7, 2025

Description

The FastAPI and Flask extensions for actors serialise the value of any raised DaprInternalError to JSON, which fails if the error contains bytes in its _raw_response_bytes field.

This change adds a new as_json_safe_dict method and uses it in place of the as_dict method in the FastAPI and Flask extensions.

Two unit tests for the as_json_safe_dict method are included.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #761

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation (n/a)

Release Note

RELEASE NOTE: FIX When calling an actor method results in an InternalDaprError being raised, the exception details are properly returned instead of a json serialisation error

The FastAPI and Flask extensions for actors serialise the value of
any raised DaprInternalError to JSON, which fails if the error
contains bytes in its `_raw_response_bytes` field.

This change adds a new `as_json_safe_dict` method and uses it in
place of the `as_dict` method in the FastAPI and Flask extensions.

Two unit tests for the `as_json_safe_dict` method are included.

Signed-off-by: Billy Brown <druidofluhn@gmail.com>
@Druid-of-Luhn Druid-of-Luhn requested review from a team as code owners January 7, 2025 11:44
@elena-kolevska elena-kolevska merged commit 0f6e96a into dapr:main Jan 9, 2025
13 checks passed
@elena-kolevska
Copy link
Contributor

@holopin-bot @Druid-of-Luhn Thanks for your contribution!

@holopin-bot
Copy link

holopin-bot bot commented Jan 9, 2025

Looks like @elena-kolevska is trying to award a sticker, but something went wrong while doing so. See this page for more information.

@codecov
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Project coverage is 86.13%. Comparing base (bffb749) to head (7000b63).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
ext/dapr-ext-fastapi/dapr/ext/fastapi/actor.py 42.85% 4 Missing ⚠️
ext/flask_dapr/flask_dapr/actor.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #765      +/-   ##
==========================================
- Coverage   86.63%   86.13%   -0.50%     
==========================================
  Files          84       89       +5     
  Lines        4473     4978     +505     
==========================================
+ Hits         3875     4288     +413     
- Misses        598      690      +92     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Druid-of-Luhn
Copy link
Contributor Author

Thanks @elena-kolevska for your suggested approach in the original issue! It was also quite a nice codebase to contribute to.

@marcduiker
Copy link
Contributor

@holopin-bot @Druid-of-Luhn Thank you! Here's a digital badge as a small token of appreciation.

@holopin-bot
Copy link

holopin-bot bot commented Jan 10, 2025

Congratulations @Druid-of-Luhn, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cm5qyr2bl55350clbu2bfdb2u

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

elena-kolevska added a commit to elena-kolevska/python-sdk that referenced this pull request Jan 14, 2025
The FastAPI and Flask extensions for actors serialise the value of
any raised DaprInternalError to JSON, which fails if the error
contains bytes in its `_raw_response_bytes` field.

This change adds a new `as_json_safe_dict` method and uses it in
place of the `as_dict` method in the FastAPI and Flask extensions.

Two unit tests for the `as_json_safe_dict` method are included.

Signed-off-by: Billy Brown <druidofluhn@gmail.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>
elena-kolevska added a commit that referenced this pull request Jan 14, 2025
* Removes support for 3.8 and adds 3.13 to test version matrix (#763)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Updates protos and fixes grpc-tools for protos generation (#766)

* Updates protos and fixes grpc-tools for protos generation

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* bumps grpcio tools version

Signed-off-by: Elena Kolevska <elena@kolevska.com>

---------

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Add DaprInternalError.as_json_safe_dict for actors (#765)

The FastAPI and Flask extensions for actors serialise the value of
any raised DaprInternalError to JSON, which fails if the error
contains bytes in its `_raw_response_bytes` field.

This change adds a new `as_json_safe_dict` method and uses it in
place of the `as_dict` method in the FastAPI and Flask extensions.

Two unit tests for the `as_json_safe_dict` method are included.

Signed-off-by: Billy Brown <druidofluhn@gmail.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* workflows: update durabletask dependency (#757)

* Bump codecov/codecov-action from 4 to 5 (#753)

      Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v4...v5)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* update durabletask to use fork

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* add purge workflow function

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* support reuse id policy

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* support set custom status

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Update ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Update ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Update ext/dapr-ext-workflow/tests/test_workflow_client.py

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Update ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* update test, grpc version and lint

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Adds missing arguments in FakeTaskHubGrpcClient

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* linter

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* remove alpha for workflow stable release (#760)

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Replace deprecated tox.ini option (#762)

This option was replaced in 2020, deprecated, and eventually removed in
tox 4. The correct option already appears elseware in this tox.ini file.

This fix is necessary to run `tox -e doc` per the README.md
instructions on tox 4.

Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Add Actor Mocks (#750)

* Moved files to new branch to avoid weird git bug

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* requested documentation changes

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* forgot to move file back to starting point

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* result of ruff format

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* fixed minor formatting issues, fixed type issues

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* minor test fix

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* fixes try_add_state

Signed-off-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* Revert "fixes try_add_state"

This reverts commit 254ad17.

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* Update dapr/actor/runtime/mock_state_manager.py

Fixing bug in try_add_state as mentioned in PR #756

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* Update dapr/actor/runtime/mock_actor.py

Whoops missed this

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* minor error in docs

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* fixed and added more unit tests. Added example

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* unittest fix

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* Update examples/demo_actor/README.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* concentrated some tests

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* removed unnecessary type hint

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* Update daprdocs/content/en/python-sdk-docs/python-actor.md

didnt see this earlier whoops

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* Update examples/demo_actor/README.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>

* documentation changes

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* now requires #type: ignore

Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>

* small docs change

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* examples test fix

Signed-off-by: Elena Kolevska <elena@kolevska.com>

---------

Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Co-authored-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
Co-authored-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Fixes try_add_state in actor state manger (#756)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Integration test for http invocation (#758)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* fixes missing state store in test (#759)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Mark workflows API functions as deprecated  (#749)

* workflows, remove deprecated functions

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>

* revert changes to example

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>

* update warning messages

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>

* Typos

Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>

* fixes linter

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Apply suggestions from code review

Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>

---------

Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Co-authored-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Removes support for 3.8 and adds 3.13 to test version matrix (#763)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Updates dapr email to dapr.io (#764)

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Reverts grpc bump

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Updates protos and fixes grpc-tools for protos generation (#766)

* Updates protos and fixes grpc-tools for protos generation

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* bumps grpcio tools version

Signed-off-by: Elena Kolevska <elena@kolevska.com>

---------

Signed-off-by: Elena Kolevska <elena@kolevska.com>

* Bump dapr/durabletask version

Signed-off-by: Elena Kolevska <elena@kolevska.com>

---------

Signed-off-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Co-authored-by: Elena Kolevska <elena@kolevska.com>
Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
Co-authored-by: Eric Searcy <emsearcy@gmail.com>
Co-authored-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Co-authored-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>

---------

Signed-off-by: Elena Kolevska <elena@kolevska.com>
Signed-off-by: Billy Brown <druidofluhn@gmail.com>
Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
Signed-off-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Signed-off-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
Signed-off-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Co-authored-by: Billy Brown <Druid-of-Luhn@users.noreply.github.com>
Co-authored-by: Fabian Martinez <46371672+famarting@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
Co-authored-by: Eric Searcy <emsearcy@gmail.com>
Co-authored-by: Lorenzo Curcio <Lorenzocurcio2@gmail.com>
Co-authored-by: Lorenzo Curcio <Lorenzo.curcio@valuecuberesearch.com>
@elena-kolevska elena-kolevska added this to the v1.15 milestone Jan 28, 2025
@elena-kolevska elena-kolevska changed the title Add DaprInternalError.as_json_safe_dict for actors [Bug] Add DaprInternalError.as_json_safe_dict for actors Jan 28, 2025
@elena-kolevska elena-kolevska changed the title [Bug] Add DaprInternalError.as_json_safe_dict for actors [BUG] Add DaprInternalError.as_json_safe_dict for actors Jan 28, 2025
elena-kolevska added a commit to elena-kolevska/python-sdk that referenced this pull request Mar 6, 2025
The FastAPI and Flask extensions for actors serialise the value of
any raised DaprInternalError to JSON, which fails if the error
contains bytes in its `_raw_response_bytes` field.

This change adds a new `as_json_safe_dict` method and uses it in
place of the `as_dict` method in the FastAPI and Flask extensions.

Two unit tests for the `as_json_safe_dict` method are included.

Signed-off-by: Billy Brown <druidofluhn@gmail.com>
Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Elena Kolevska <elena@kolevska.com>
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.

[BUG] InternalDaprError in actor method call can cause serialisation error when returning exception details

3 participants