flow-py-sdk
flow-py-sdk copied to clipboard
#66/ Deserializing of events from flow_proto fails with transactions with many events
Resolves issue #66
Summary by CodeRabbit
Release Notes
-
New Features
- Introduced a new example for debugging transaction fetching by ID.
- Added a new JSON structure for event capabilities, enhancing metadata representation.
- Added a new test for account capability event encoding and decoding.
-
Bug Fixes
- Improved error handling and logging for event deserialization and transaction results.
-
Chores
- Updated
.gitignoreto includemyenvfor better environment management. - Renamed
AuthAccountKindtoAccountKindfor clarity in naming conventions.
- Updated
[!WARNING]
Rate limit exceeded
@lealobanov has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 12 seconds before requesting another review.
⌛ How to resolve this issue?
After the wait time has elapsed, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.We recommend that you space out your commits to avoid hitting the rate limit.
🚦 How do rate limits work?
CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.
📥 Commits
Reviewing files that changed from the base of the PR and between 44093828450699505ee05e8925a055d42b40138e and d8c9f6aaa1edafa543fc091857f4d1121c75f3b9.
Walkthrough
The changes in this pull request introduce several new features and modifications across multiple files. A new class, DebuggingFetchTransactionByIdExample, is added to provide an example for fetching transactions by ID. A new JSON structure is established in failed_events.json to detail event capabilities. The decode function in flow_py_sdk/cadence/decode.py is enhanced to handle errors and improve functionality. Changes in flow_py_sdk/cadence/kinds.py simplify the decode method in the EntitlementsKind class. Additionally, significant error handling improvements are made in flow_py_sdk/client/entities.py, particularly for event deserialization. Lastly, .gitignore is updated to ignore the myenv directory.
Changes
| File | Change Summary |
|---|---|
| examples/transactions_examples.py | Added new class DebuggingFetchTransactionByIdExample for fetching transaction by ID. |
| failed_events.json | Introduced a new JSON structure with event objects detailing capabilities and metadata. |
| flow_py_sdk/cadence/decode.py | Modified decode function to handle errors and updated signature to return a dictionary. |
| flow_py_sdk/cadence/kinds.py | Simplified return statement in decode method of EntitlementsKind class. |
| flow_py_sdk/client/entities.py | Enhanced error handling and logging in Event and TransactionResultResponse classes. |
| .gitignore | Added entry for myenv to ignore virtual environment files. |
| flow_py_sdk/cadence/init.py | Renamed AuthAccountKind to AccountKind in import statements. |
| flow_py_sdk/cadence/simple_kinds.py | Renamed AuthAccountKind class to AccountKind and updated kind_str method. |
| tests/cadence/encode_test.py | Added new test method testAccountCapabilityControllerIssued and modified testStorefrontEvent. |
Possibly related PRs
- #62: The changes in
examples/transactions_examples.pyin the main PR introduce a new class for fetching transactions, while the retrieved PR modifies thepreparefunction in the same file, indicating a direct relationship in terms of functionality related to transactions.
Poem
In the code where rabbits play,
New examples hop and sway.
Fetching transactions, oh what fun,
With logs and errors, we’ve just begun!
Ignore myenv, let’s keep it neat,
In this code, our joys repeat! 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
:warning: Please install the to ensure uploads and comments are reliably processed by Codecov.
Codecov Report
Attention: Patch coverage is 40.81633% with 29 lines in your changes missing coverage. Please review.
Project coverage is 83.93%. Comparing base (
ac0bbb9) to head (d8c9f6a).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| flow_py_sdk/client/entities.py | 4.54% | 21 Missing :warning: |
| flow_py_sdk/cadence/decode.py | 66.66% | 6 Missing and 2 partials :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@
## master #67 +/- ##
==========================================
- Coverage 84.79% 83.93% -0.87%
==========================================
Files 29 29
Lines 1927 1954 +27
Branches 102 105 +3
==========================================
+ Hits 1634 1640 +6
- Misses 277 297 +20
- Partials 16 17 +1
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 83.93% <40.81%> (-0.87%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hi @janezpodhostnik ,
- Just updated the exception handling to raise an exception and exit the decoding if one of the events failed to decode (instead of continuing).
I think the source of the bug might have been the recent migration to Cadence 1.0, as I noticed all of the events which failed to decode had complex nested dict/list fields such as authorizations and staticType found in the EntitlementConjunctionSet class. Entitlements seem to be a new syntax introduced since the C1.0 release (https://www.youtube.com/watch?v=aZ1aCBtPpXo), so I suspect this might be why this wasn't throwing an error before.
Some other preventative measures we could take on the decoding of events array:
- Imposing a max number of events that get decoded per transaction
- Imposing a max limit on event payload size
Initially I tested out both of these changes, but ultimately this TX id ended up decoding successfully once I updated to decode the nested structures. So for now I think it's ok to skip on the above 2 items and potentially reconsider if events will continue to cause issues.
Thanks!
Just updated the exception handling to raise an exception and exit the decoding if one of the events failed to decode (instead of continuing).
Looks great, thank you. Can you do the same for flow_py_sdk/client/entities.py
I did some digging. And I realized that the recursive decoding should not be needed, since the cadence json api objects already define if something can be a list or not, and the EntitlementsKind do correctly accept a list.
class EntitlementsKind(Kind, ABC):
def __init__(self, entitlements: list[EntitlementBaseKind]) -> None:
The error was that an element that should have been decoded was not due to the incorrect naming of "Account" (it was still "AuthAccount" since I forgot to change it from before cadence 1.0)
Changing that fixed the issue without the need of adding the recursive decoding.
If you want to pull those changes in your PR and cleanup the temporary things we can get this merged.
As for this:
Some other preventative measures we could take on the decoding of events array:
Imposing a max number of events that get decoded per transaction Imposing a max limit on event payload size
That is a great idea, and the contribution would be much appreciated, but lets not add it to this PR to keep it smaller and because its supposed to be a bugfix.
Hi @janezpodhostnik ,
Good catch, I didn't notice that the naming of the field had changed - thank you so much for looking into it. I've just pulled in your branch and cleaned up the test code. I've run the latest changes against tx ID ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71 and can confirm it decoded successfully, so have gone ahead and removed this from the transaction_examples file.