Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ValueError: Object 'EXCLUDE' is not a valid value for the 'unknown' parameter #110

Open
Cyb3rFl3x opened this issue Jul 21, 2022 · 3 comments

Comments

@Cyb3rFl3x
Copy link

I'm not quite sure why the example code from dynamorm documentation is not working...

  1. installed marshmallow & dynamorm
  2. i copied you example code
  3. i setup a dynamodb on aws
  4. I got the following error (ValueError: Object 'EXCLUDE' is not a valid value for the 'unknown' parameter)

Seems like the error is coming from the SchemaMeta class of Marshmallow (see: line 393 in marshmallow/schema.py)
It always jumps inside the validate_unknown_parameter_value function. Even if i use predefined unknown vars from Marshmallow documentation... Some one of you have maybe an idea?

self.unknown = (
   self.opts.unknown
   if unknown is None
   else validate_unknown_parameter_value(unknown)
)
@Cyb3rFl3x
Copy link
Author

After playing around with the versions of marshmallow, I figured out, that the problem exists only when using version 3.17 of marshmallow in combination with dynamorm version 0.11.0.

@mvsantos013
Copy link

Using dynamorm 0.11.0 with marshmallow 3.15.0 worked for me. Got error with 3.16.0 and 3.17.0.

@adamlukaszewski
Copy link

Hi folks,

I guess that this is a very simple to fix. I ran into the same issue using dynamorm 0.11.0 and marshmallow 3.20.1. I debugged a little bit the logic and the reason for the error is, that during the validation of the feed dynamorm is using and incorrect value for the unknown parameter:

# Define different validation logic depending on the version of marshmallow we're using
if parse_version(marshmallow_version) >= parse_version("3.0.0a1"):

    def _validate(cls, obj, partial=False, native=False):
        """Validate using a Marshmallow v3+ schema"""
        try:
            if native:
                data = cls().load(obj, partial=partial, unknown="EXCLUDE")
            else:
                data = cls(partial=partial, unknown="EXCLUDE").dump(obj)
        except MarshmallowError as e:
            raise ValidationError(obj, cls.__name__, e)
        return data

The unknown="EXCLUDE" parameter set the unknown argument as upper case String, but the marshmallow is expecting the following:

"""Utility methods for marshmallow."""
from __future__ import annotations

EXCLUDE = "exclude"
INCLUDE = "include"
RAISE = "raise"
_UNKNOWN_VALUES = {EXCLUDE, INCLUDE, RAISE}

So changing the _validateto use (lower case string or constant):

 data = cls().load(obj, partial=partial, unknown="exclude")

or (better):

from marshmallow import Schema as MarshmallowSchema, EXCLUDE

...

 data = cls().load(obj, partial=partial, unknown=EXCLUDE)

completely resolved the error. It seems that we are able to use things as expected then.

How can I contribute the bugfix so that this wonderful library becomes more stable :)?

ax-brendani added a commit to ax-brendani/dynamorm that referenced this issue Oct 11, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants