Skip to content
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

Chore: fix marshmallow warnings #2398

Merged

Conversation

ff137
Copy link
Contributor

@ff137 ff137 commented Aug 5, 2023

Resolves #2342

I used the acapy-marshmallow-upgrade tool created by @dbluhm (as described here: #1854 (comment)), which iterates over usages of marshmallow fields, to wrap deprecated arguments in a metadata dictionary.

The only hairy part to this task was the schemas defined in aries_cloudagent/messaging/valid.py:

INT_EPOCH = {"validate": IntEpoch(), "example": IntEpoch.EXAMPLE}
WHOLE_NUM = {"validate": WholeNumber(), "example": WholeNumber.EXAMPLE}
# etc ...

These definitions were used in marshmallow fields by calling e.g. fields.Int(..., **INT_EPOCH), which would be missed by the upgrade tool. Also, validate is a supported argument, while example should be moved to metadata.

To account for this, I refactored the schema specifications (using regex):

INT_EPOCH_VALIDATE = IntEpoch()
INT_EPOCH_EXAMPLE = IntEpoch.EXAMPLE

WHOLE_NUM_VALIDATE = WholeNumber()
WHOLE_NUM_EXAMPLE = WholeNumber.EXAMPLE
# etc ...

I then updated the imports, and replaced usages of **INT_EPOCH, for example, to validate=INT_EPOCH_VALIDATE, example=INT_EPOCH_EXAMPLE. Then could I run the marshmallow-upgrade tool created by dbluhm to correctly wrap examples in the metadata.

Additionally: upgrade marshmallow to latest (3.20)

ff137 added 20 commits August 5, 2023 11:59
…d example cases, in order to run marshmallow metadata upgrade

Signed-off-by: ff137 <[email protected]>
…d example cases, in order to run marshmallow metadata upgrade (openwallet-foundation#2342)

Signed-off-by: ff137 <[email protected]>
…foundation#2342)

Utilized the custom upgrade tool from the `dbluhm/acapy-marshmallow-upgrade` repository to modify the marshmallow field definitions in accordance with the latest best practices. This update eliminates the deprecation warnings related to marshmallow usage in ACA-Py.

Signed-off-by: ff137 <[email protected]>
Signed-off-by: ff137 <[email protected]>
Signed-off-by: ff137 <[email protected]>
Signed-off-by: ff137 <[email protected]>
Signed-off-by: ff137 <[email protected]>
@ff137 ff137 marked this pull request as ready for review August 5, 2023 12:53
@ff137
Copy link
Contributor Author

ff137 commented Aug 5, 2023

1'108 marshmallow deprecation warnings reduced to 18 :-)
I'll review the remaining ones and add changes

@ff137 ff137 marked this pull request as draft August 5, 2023 12:56
@ff137 ff137 marked this pull request as ready for review August 5, 2023 14:06
@ff137
Copy link
Contributor Author

ff137 commented Aug 5, 2023

There is now only 1 more marshmallow deprecation warning (that occurs 45 times?)

aries_cloudagent/admin/tests/test_admin_server.py: 45 warnings
   /opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/apispec/ext/marshmallow/field_converter.py:213: RemovedInMarshmallow4Warning: The 'missing' attribute of fields is deprecated. Use 'load_default' instead.
     default = field.missing

There's no usage of the missing attribute in the codebase, so perhaps it's arising from a dependency - hard to tell

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@dbluhm
Copy link
Contributor

dbluhm commented Aug 7, 2023

@ff137 looks like updating apispec (current version installed is 3.3.0; upstream is 6.3.0) should take care of those last warnings. Might be worth updating aiohttp-apispec along with it (current version installed is 2.2.1; upstream is 2.2.3). That being said, we can handle that in another PR.

Copy link
Contributor

@dbluhm dbluhm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Glad the script I wrote was helpful. I seem to remember taking a similar tactic on those splatted kwargs from messaging.valid.

Heads up, @swcurran @usingtechnology, this is a big change by number of lines but behavior of these models is unchanged. I think we should merge this quickly since addressing merge conflicts could be a bit extra painful.

This should merge cleanly into the anoncreds-rs branch but the new models defined there would need some adjustment. I can assist there. Even if the models weren't adjusted immediately, we'll get warnings reported to help track them down later.

@swcurran swcurran merged commit d8dfdd0 into openwallet-foundation:main Aug 7, 2023
@swcurran
Copy link
Contributor

swcurran commented Aug 7, 2023

I leave it to you to define how to merge into the anoncreds-rs branch.

@swcurran
Copy link
Contributor

swcurran commented Aug 7, 2023

Oh and awesome to get these cleaned up — nice work!!

@usingtechnology
Copy link
Contributor

I leave it to you to define how to merge into the anoncreds-rs branch.

@dbluhm - i am in the middle of a first PR to the anoncreds-rs branch (cleanup, basically). Let me get that in place then we can do a merge of all this work. holiday day here in BC but will see if I can get that PR up for review sometime today.

@ff137 ff137 deleted the chore/fix-marshmallow-warnings branch July 4, 2024 22:09
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.

Update marshmallow usage to remove deprecation warnings
4 participants