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.

Possible bug for Marshmallow fields

See original GitHub issue

I’ve been having trouble setting up default values for the Integer field. I tried using both load_default and default parameters to no avail. It still resulted in the following error message:

{
  "Code": 422, 
  "errors": {
    "query": {
      "page": [
        "Not a valid integer."
      ]
    }
  }
}

In the Schema, I also have a string field. As I am using webargs, I removed the user parameter from the url, and I did get an error message coming from the string field that was similar to the integer one. I’m not sure whether I did something wrong when assigning default values but if I didn’t, then there might be a potential bug with the source code for marshmallow.

Schema:


class AccountUserManagementWebArgs(Schema):
    """
    account user management schema
    """

    user = fields.String(required=True)
    page = fields.Integer(default=1)
    actions = fields.Nested(_account_user_management_webargs_nested, many=True)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lafrechcommented, Sep 19, 2021

I won’t dig through the whole code sample but

The main goal is that the default value for a schema item should be returned as None if it isn’t found in the url parameter

  "page": [
    "Not a valid integer."
  ]

Could it be you parser sets None as default for all query args, including pagination query args and then you get None for page, which is invalid?

(You may try to send a request with a value for page and see what happens.)

0reactions
lafrechcommented, Sep 21, 2021

Great. Closing this, then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog — marshmallow 3.19.0 documentation
Fix bug that raised an AttributeError when instantiating a Schema with a field named ... It makes it possible to either “include”, “exclude”,...
Read more >
Method Errors Cause Missing Field #993 - GitHub
It looks like marshmallow 2.x is swallowing exceptions indiscriminately and ignoring the field. The issue does not seem to be present in ...
Read more >
marshmallow - Read the Docs
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. from datetime ...
Read more >
top-level marshmallow schema validation - Stack Overflow
My question : Is it possible to validate at the Schema level (rather than at individual field level) and still return an error...
Read more >
Toasted Marshmallow — Marshmallow but 15X Faster.
Marshmallow is slow because it's effectively implementing an interpreter in an interpreter. When you serialize an object through Marshmallow it ...
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