Skip to content

fix(mm): Replace deprecated Marshmallow Field parameters #351

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevenpackardblp
Copy link

In Marshmallow 3.13.0, the default and missing parameters of the
Field object were deprecated and replaced with dump_default and
load_default respectively. As these are new parameters added in
version 3.13.0, the minimum version requirement is bumped accordingly.

fixes: #328

@stevenpackardblp
Copy link
Author

This would be nice to clean up the warning spews!

@camin-mccluskey
Copy link

In case anyone is seeing hundreds of errors, is waiting on this fix to be merged (and uses pytest) adding the following to a pytest.ini file will suppress these warnings:

[pytest]
filterwarnings =
    ignore::DeprecationWarning:marshmallow*
    ignore::DeprecationWarning:dataclasses_json*

@andret13pinto
Copy link

I would love for this fix to be merged!

@george-zubrienko
Copy link
Collaborator

@stevenpackardblp please update your PR and we can merge ;)

@george-zubrienko
Copy link
Collaborator

@stevenpackardblp another ping :) if no reply in a week I'll take over this PR and re-create it

@george-zubrienko george-zubrienko self-assigned this Jul 20, 2023
@stevenpackardblp
Copy link
Author

@stevenpackardblp another ping :) if no reply in a week I'll take over this PR and re-create it

Let me refresh my workspace this week and see if I can get this rebased. Apologies for missing the first ping.

@russwinch
Copy link

it would be great if this could be merged 🙏

@rbreslavsky
Copy link

Agree, would be great if this could be addressed!

@stevenpackardblp
Copy link
Author

@george-zubrienko big apologies for the delay, I just rebased it.

@stevenpackardblp
Copy link
Author

rebased again.

@nomantis
Copy link

nomantis commented Aug 1, 2024

It would be great to get this merged, so the deprecation warnings can finally be addressed 🙏

In Marshmallow 3.13.0, the `default` and `missing` parameters of the
`Field` object were deprecated and replaced with `dump_default` and
`load_default` respectively.

fixes: lidatong#328
@stevenpackardblp
Copy link
Author

rebased again

@PPN-SD
Copy link

PPN-SD commented May 13, 2025

It would be possible to solve the other issues with marshmallow4 ?

tests/test_api.py: 3 warnings
tests/test_schema.py: 1 warning
tests/test_union.py: 20 warnings
  /usr/lib/python3.13/site-packages/marshmallow/fields.py:582: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'field_many': False}
    super().__init__(default=default, dump_default=dump_default, **kwargs)

tests/test_api.py::TestSchema::test_dumps_new_type
  /var/tmp/portage/dev-python/dataclasses-json-0.6.7/work/dataclasses-json-0.6.7/dataclasses_json/mm.py:288: UserWarning: Unknown type tests.entities.UUIDWrapper at DataClassWithNewType.id: tests.entities.UUIDWrapper It's advised to pass the correct marshmallow type to `mm_field`.    warnings.warn(

tests/test_api.py::TestSchema::test_dumps_new_type
tests/test_api.py::TestSchema::test_dumps_nested_new_type
tests/test_recursive.py::TestRecursive::test_tree_schema_round_trip
  /var/tmp/portage/dev-python/dataclasses-json-0.6.7/work/dataclasses-json-0.6.7/dataclasses_json/mm.py:291: ChangedInMarshmallow4Warning: `Field` should not be instantiated. Use `fields.Raw` or  another field subclass instead.
    return fields.Field(**options)

tests/test_api.py::TestSchema::test_dumps_nested_new_type
  /var/tmp/portage/dev-python/dataclasses-json-0.6.7/work/dataclasses-json-0.6.7/dataclasses_json/mm.py:288: UserWarning: Unknown type tests.entities.UUIDWrapperWrapper at DataClassWithNestedNewType.id: tests.entities.UUIDWrapperWrapper It's advised to pass the correct marshmallow type to `mm_field`.    warnings.warn(

@mweinelt
Copy link

Wondering if it is as simple as

diff --git a/dataclasses_json/mm.py b/dataclasses_json/mm.py
index 9cfacf1..cecd3b0 100644
--- a/dataclasses_json/mm.py
+++ b/dataclasses_json/mm.py
@@ -248,7 +248,7 @@ def build_type(type_, options, mixin, field, cls):
                 options['field_many'] = bool(
                     _is_supported_generic(field.type) and _is_collection(
                         field.type))
-                return fields.Nested(type_.schema(), **options)
+                return fields.Nested(type_.schema(), metadata=options)
             else:
                 warnings.warn(f"Nested dataclass field {field.name} of type "
                               f"{field.type} detected in "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Marshmallow warnings
9 participants