MongoEngine / MongoEngine/mongoengine
MongoEngine: Embeddeddocument fields do not take default value as none?
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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