MongoEngine / MongoEngine/mongoengine

MongoEngine: Embeddeddocument fields do not take default value as none?

Open
#1,325 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

I've set the default values for fields in embedded document but when I try to post data it doesn't accept None or Blank values.

Here is what my code looks like-

models.py

class MetaData(EmbeddedDocument):
    adcode = StringField(max_length=50, default="", blank=True, Null=True)
    additional_html_below_header = StringField(max_length=50, default="")
    adhoc_plus_disable_pacing = BooleanField(default=False)
    adhoc_plus_has_priority = BooleanField(default=False)
    adhoc_server = StringField(max_length=50, default="")
class LandingPage(Document):
    type = StringField(max_length=50, default="")
    meta_clean_URL_tag = StringField(max_length=50, default="")
    meta_name =  StringField(max_length=50, default="")
    created_time = DateTimeField(default=datetime.datetime.now)
    new = BooleanField(default=False)
    meta_data = EmbeddedDocumentField(MetaData)

serializers.py

class MetaDataSerializer(serializers.EmbeddedDocumentSerializer):
    class Meta:
        model = MetaData

class LandingPageSerializer(serializers.DocumentSerializer):
    meta_data = MetaDataSerializer()
    class Meta:
        model = LandingPage

Is there anything wrong I'm doing here?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the field declarations in models.py and the EmbeddedDocumentSerializer and DocumentSerializer definitions in serializers.py. Reproduce the reported handling of None and blank values, then establish whether the model defaults or serializer behavior is responsible; the issue is complete when the expected embedded-document behavior is defined and verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.