question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

marshmalling.Unmarshaller ignoring None data

See original GitHub issue

marshmalling.Unmarshaller seems to ignore None data and don’t try to validate passed data, even if there is required fields.

What the point having a validation library if we have to validate ourselves the “basic” case of None data?

Just asking the question, because it really doesn’t seems logical to me (and because I had to handle myself this issue in my own code…)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
sloriacommented, Jan 6, 2016

Schema#load and Schema#validate responsibility is to validate dict data, by default. None, False, numbers, as well as arbitrary complex objects, are outside their API boundary.

As mentioned above, you can use pre_load to preprocess inputs before they are validated.

from marshmallow import Schema, fields, pre_load

class MySchema(Schema):
    required_field = fields.Field(required=True)

    @pre_load
    def ensure_dict(self, data):
        return data or {}

schema = MySchema()
print(schema.validate(None))
# {'required_field': ['Missing data for required field']}
0reactions
sloriacommented, Feb 14, 2016

There’s this section of the docs: https://marshmallow.readthedocs.org/en/latest/quickstart.html#deserializing-objects-loading

The opposite of the dump method is the load method, which deserializes an input dictionary to an application-level data structure.

The API ref for load also specifies that the data argument is a dict: https://marshmallow.readthedocs.org/en/latest/api_reference.html#marshmallow.Schema.load .

I welcome any suggestions for making this clearer. Send a PR if you’re feeling generous! =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - JAXB unmarshalling ignoring namespace turns element ...
I've attempted numerous ways of specifying it in the XSD but none of the permutations seem to work. I also attempted to unmarshal...
Read more >
Marshalling (computer science) - Wikipedia
An unmarshalling interface takes a serialized object and transforms it into an internal data structure. The accurate definition of marshalling differs across ...
Read more >
JAXB - Apache Camel
JAXB is a Data Format which uses the JAXB2 XML marshalling standard to unmarshal an ... To ignore non xml characheters and replace...
Read more >
Encoding Infinispan caches and marshalling data
For clustered embedded caches, Infinispan needs to marshall any POJOs to a byte array that can be replicated between nodes and then unmarshalled...
Read more >
JAXB / MOXy - not unmarshalling values after ignored elements
I'm working on a JAXB/MOXy XML parsing implementation using EclipseLink v2.1.3 (old, I know but we're still tied to Java 5) and I've ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found