Skip to content

_deserialize() got an unexpected keyword argument 'partial' #3

Description

@passitalong

I am getting an error of "_deserialize() got an unexpected keyword argument 'partial'" when I attempt to deserialize with Marshmallow.

  File "/Users/seanhoward/.virtualenvs/MegaTronWeb/lib/python3.9/site-packages/marshmallow/fields.py", line 365, in deserialize
    output = self._deserialize(value, attr, data, **kwargs)
TypeError: _deserialize() got an unexpected keyword argument 'partial'

MA2 appears to require **kwargs be added to all custom serialize/deserialize functions.

see: (marshmallow-code/marshmallow#1286)

I changed _serialize and _deserialize to include , **kwargs and it appears to be working.

class ArrowField(fields.Field):
    """
    An isoformatted datetime string.

    Arrow objects are converted to and from isoformatted strings
    by `Schema.dump` and `Schema.load` respectively.
    """

    default_error_messages = {
        'invalid_object': 'Invalid arrow object.',
        'invalid_datetime': 'Unable to parse datetime.',
    }

    def _serialize(self, value, attr, obj, **kwargs):
        if value is None:
            return None

        return value.isoformat()

    def _deserialize(self, value, attr, data, **kwargs):
        if not value:
            raise self.fail('invalid_object')

        try:
            return arrow.get(value)
        except arrow.parser.ParserError:
            raise self.fail('invalid_datetime')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions