marshmallow-mongoengine:Output dump value missing 'None' fieldMongoengine - id field is named NoneMongoEngine — how to custom User model / custom backend for authenticate()Separate mongoengine models in django 1.7How to specify label_attr for a model in a Flask-Admin ModelView using MongoEngine?mongoengine and django rest framework - fields aren't allowed to be optionalUpdate fields only when new value is not NoneWorking with reference fields in marshmallow-mongoengineMongoengine : How to update specific fields of an existing document?flask-marshmallow custom fieldsHow to serialize Decimal Fields in mongoengine marshmallow?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

What is Cash Advance APR?

Doesn't the system of the Supreme Court oppose justice?

Giving feedback to someone without sounding prejudiced

Delete multiple columns using awk or sed

Does the reader need to like the PoV character?

Make a Bowl of Alphabet Soup

When were female captains banned from Starfleet?

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

Is there any evidence that Cleopatra and Caesarion considered fleeing to India to escape the Romans?

Why is the Sun approximated as a black body at ~ 5800 K?

Pre-mixing cryogenic fuels and using only one fuel tank

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

Biological Blimps: Propulsion

Can I say "fingers" when referring to toes?

Mimic lecturing on blackboard, facing audience

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

How does electrical safety system work on ISS?

The IT department bottlenecks progress, how should I handle this?

What is going on with gets(stdin) on the site coderbyte?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Why do ¬, ∀ and ∃ have the same precedence?

A variation to the phrase "hanging over my shoulders"

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?



marshmallow-mongoengine:Output dump value missing 'None' field


Mongoengine - id field is named NoneMongoEngine — how to custom User model / custom backend for authenticate()Separate mongoengine models in django 1.7How to specify label_attr for a model in a Flask-Admin ModelView using MongoEngine?mongoengine and django rest framework - fields aren't allowed to be optionalUpdate fields only when new value is not NoneWorking with reference fields in marshmallow-mongoengineMongoengine : How to update specific fields of an existing document?flask-marshmallow custom fieldsHow to serialize Decimal Fields in mongoengine marshmallow?













0















My project uses flask+mongoengine+marshmallow,When I used marshmallow to serialize the model, the returned value lacked field, and the missing field value was None.When using Django to serialize fields, the None value is still output
model



class Author(db.Document):
name = db.StringField()
gender = db.IntField()
books = db.ListField(db.ReferenceField('Book'))

def __repr__(self):
return '<Author(name=self.name!r)>'.format(self=self)


class Book(db.Document):
title = db.StringField()


serializers



class AuthorSchema(ModelSchema):
class Meta:
model = Author


class BookSchema(ModelSchema):
class Meta:
model = Book

author_schema = AuthorSchema()


When I do this:



author = Author(name="test1")
>>> author.save()
<Author(name='test1')>
>>> author_schema.dump(author)
MarshalResult(data='id': '5c80a029fe985e42fb4e6299', 'name': 'test1', errors=)
>>>



not return the books field
I hope to return




"name":"test1",
"books": None



what should I do?










share|improve this question


























    0















    My project uses flask+mongoengine+marshmallow,When I used marshmallow to serialize the model, the returned value lacked field, and the missing field value was None.When using Django to serialize fields, the None value is still output
    model



    class Author(db.Document):
    name = db.StringField()
    gender = db.IntField()
    books = db.ListField(db.ReferenceField('Book'))

    def __repr__(self):
    return '<Author(name=self.name!r)>'.format(self=self)


    class Book(db.Document):
    title = db.StringField()


    serializers



    class AuthorSchema(ModelSchema):
    class Meta:
    model = Author


    class BookSchema(ModelSchema):
    class Meta:
    model = Book

    author_schema = AuthorSchema()


    When I do this:



    author = Author(name="test1")
    >>> author.save()
    <Author(name='test1')>
    >>> author_schema.dump(author)
    MarshalResult(data='id': '5c80a029fe985e42fb4e6299', 'name': 'test1', errors=)
    >>>



    not return the books field
    I hope to return




    "name":"test1",
    "books": None



    what should I do?










    share|improve this question
























      0












      0








      0


      1






      My project uses flask+mongoengine+marshmallow,When I used marshmallow to serialize the model, the returned value lacked field, and the missing field value was None.When using Django to serialize fields, the None value is still output
      model



      class Author(db.Document):
      name = db.StringField()
      gender = db.IntField()
      books = db.ListField(db.ReferenceField('Book'))

      def __repr__(self):
      return '<Author(name=self.name!r)>'.format(self=self)


      class Book(db.Document):
      title = db.StringField()


      serializers



      class AuthorSchema(ModelSchema):
      class Meta:
      model = Author


      class BookSchema(ModelSchema):
      class Meta:
      model = Book

      author_schema = AuthorSchema()


      When I do this:



      author = Author(name="test1")
      >>> author.save()
      <Author(name='test1')>
      >>> author_schema.dump(author)
      MarshalResult(data='id': '5c80a029fe985e42fb4e6299', 'name': 'test1', errors=)
      >>>



      not return the books field
      I hope to return




      "name":"test1",
      "books": None



      what should I do?










      share|improve this question














      My project uses flask+mongoengine+marshmallow,When I used marshmallow to serialize the model, the returned value lacked field, and the missing field value was None.When using Django to serialize fields, the None value is still output
      model



      class Author(db.Document):
      name = db.StringField()
      gender = db.IntField()
      books = db.ListField(db.ReferenceField('Book'))

      def __repr__(self):
      return '<Author(name=self.name!r)>'.format(self=self)


      class Book(db.Document):
      title = db.StringField()


      serializers



      class AuthorSchema(ModelSchema):
      class Meta:
      model = Author


      class BookSchema(ModelSchema):
      class Meta:
      model = Book

      author_schema = AuthorSchema()


      When I do this:



      author = Author(name="test1")
      >>> author.save()
      <Author(name='test1')>
      >>> author_schema.dump(author)
      MarshalResult(data='id': '5c80a029fe985e42fb4e6299', 'name': 'test1', errors=)
      >>>



      not return the books field
      I hope to return




      "name":"test1",
      "books": None



      what should I do?







      mongoengine






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 5:03









      user9998404user9998404

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          When I looked at the source code of the marshmallow-mongoengine library, I found the solution model_skip_values=() in the tests file.



          def test_disable_skip_none_field(self):
          class Doc(me.Document):
          field_empty = me.StringField()
          list_empty = me.ListField(me.StringField())
          class DocSchema(ModelSchema):
          class Meta:
          model = Doc
          model_skip_values = ()
          doc = Doc()
          data, errors = DocSchema().dump(doc)
          assert not errors
          assert data == 'field_empty': None, 'list_empty': []





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036423%2fmarshmallow-mongoengineoutput-dump-value-missing-none-field%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            When I looked at the source code of the marshmallow-mongoengine library, I found the solution model_skip_values=() in the tests file.



            def test_disable_skip_none_field(self):
            class Doc(me.Document):
            field_empty = me.StringField()
            list_empty = me.ListField(me.StringField())
            class DocSchema(ModelSchema):
            class Meta:
            model = Doc
            model_skip_values = ()
            doc = Doc()
            data, errors = DocSchema().dump(doc)
            assert not errors
            assert data == 'field_empty': None, 'list_empty': []





            share|improve this answer



























              0














              When I looked at the source code of the marshmallow-mongoengine library, I found the solution model_skip_values=() in the tests file.



              def test_disable_skip_none_field(self):
              class Doc(me.Document):
              field_empty = me.StringField()
              list_empty = me.ListField(me.StringField())
              class DocSchema(ModelSchema):
              class Meta:
              model = Doc
              model_skip_values = ()
              doc = Doc()
              data, errors = DocSchema().dump(doc)
              assert not errors
              assert data == 'field_empty': None, 'list_empty': []





              share|improve this answer

























                0












                0








                0







                When I looked at the source code of the marshmallow-mongoengine library, I found the solution model_skip_values=() in the tests file.



                def test_disable_skip_none_field(self):
                class Doc(me.Document):
                field_empty = me.StringField()
                list_empty = me.ListField(me.StringField())
                class DocSchema(ModelSchema):
                class Meta:
                model = Doc
                model_skip_values = ()
                doc = Doc()
                data, errors = DocSchema().dump(doc)
                assert not errors
                assert data == 'field_empty': None, 'list_empty': []





                share|improve this answer













                When I looked at the source code of the marshmallow-mongoengine library, I found the solution model_skip_values=() in the tests file.



                def test_disable_skip_none_field(self):
                class Doc(me.Document):
                field_empty = me.StringField()
                list_empty = me.ListField(me.StringField())
                class DocSchema(ModelSchema):
                class Meta:
                model = Doc
                model_skip_values = ()
                doc = Doc()
                data, errors = DocSchema().dump(doc)
                assert not errors
                assert data == 'field_empty': None, 'list_empty': []






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 1:31









                user9998404user9998404

                11




                11





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036423%2fmarshmallow-mongoengineoutput-dump-value-missing-none-field%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved