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

Adds a configuration option to allow mixed alias/unaliased field name use when deserializing #175

Merged
merged 8 commits into from
Nov 14, 2023

Conversation

matthew-chambers-pushly
Copy link
Contributor

@matthew-chambers-pushly matthew-chambers-pushly commented Nov 3, 2023

Problem statement:

Our company uses mashumaro extensively and have several interconnected services that use the same shared data structures; however, in some places it is useful for the serialized payloads to be human readable and in other places having the keys be "minified" using aliases is more important. To prevent needing to duplicate the dataclasses around the codebase, we use a combination of dialects and the by_alias= option to control how the data is serialized, but when the data is deserialized in the current mashumaro build the fieldnames must match the alias.

Changes:

Adds an option called loose_deserialization to the BaseConfig to allow for mixed aliased/unaliased usage during deserialization.

deserializing, and the requisite test and docs updates.
@pep8speaks
Copy link

pep8speaks commented Nov 3, 2023

Hello @matthew-chambers-pushly! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2023-11-14 15:16:43 UTC

Copy link
Owner

@Fatal1ty Fatal1ty left a comment

Choose a reason for hiding this comment

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

Hi @matthew-chambers-pushly

This is something that was on my radar! Thank you for bringing it in. However, there are some things worth paying attention to.

I think that loose_deserialization is too broad name for this feature. I'm sure there is a more accurate name for it. How about allow_deserialization_not_by_alias ?

mashumaro/core/meta/code/builder.py Outdated Show resolved Hide resolved
tests/test_aliases.py Show resolved Hide resolved
@matthew-chambers-pushly
Copy link
Contributor Author

Those mypy failures seem to be a regression introduced by mypy 1.7.

@Fatal1ty
Copy link
Owner

Those mypy failures seem to be a regression introduced by mypy 1.7.

I fixed it in master. Please, update your branch.

@Fatal1ty Fatal1ty merged commit 040ba70 into Fatal1ty:master Nov 14, 2023
27 checks passed
@Fatal1ty
Copy link
Owner

@matthew-chambers-pushly

I made some tweaks to tests and docs before the merge. Thank you for your contribution!

@matthew-chambers-pushly
Copy link
Contributor Author

@matthew-chambers-pushly

I made some tweaks to tests and docs before the merge. Thank you for your contribution!

Thank you for the library, we've shown the testing and coverage as an example to younger devs.

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.

None yet

3 participants