EmbeddedField field not accept many argument
See original GitHub issueAttributeError: ‘list’ object has no attribute ‘items’
see the stacktrace below
i have this schema
@Application.db_instance.register
class Comment(EmbeddedDocument):
user = fields.UUIDField(required=True)
text = fields.StringField(validate=validate.Length(min=3), required=True)
created = fields.DateTimeField(missing=datetime.datetime.now)
@Application.db_instance.register
class Blog(Document):
title = fields.StringField(validate=validate.Length(max=128), required=True)
text = fields.StringField(validate=validate.Length(min=128), required=True)
user = fields.UUIDField(required=True)
comments = fields.EmbeddedField(Comment, missing=[], many=True)
class Meta:
collection = Application.db.blog
my payload
{
"title": "...some title .....",
"text": "...some text... ",
"user": "e365eb8d-b802-4f57-bc58-939a870fefb5",
"comments": [
{
"user": "e365eb8d-b802-4f57-bc58-939a870fefb6",
"text": "some comments"
}
]
}
commit result
data = tornado.escape.json_decode(self.request.body)
blog = Blog(**data)
await blog.commit()
stracktrace
File "/python3.6/site-packages/umongo/document.py", line 143, in __init__
self._data = self.DataProxy(kwargs if kwargs else None)
File "/python3.6/site-packages/umongo/data_proxy.py", line 22, in __init__
self.load(data or {})
File "/python3.6/site-packages/umongo/data_proxy.py", line 99, in load
loaded_data, err = self.schema.load(data, partial=True)
File "/python3.6/site-packages/marshmallow/schema.py", line 500, in load
result, errors = self._do_load(data, many, partial=partial, postprocess=True)
File "/python3.6/site-packages/marshmallow/schema.py", line 580, in _do_load
index_errors=self.opts.index_errors,
File "/python3.6/site-packages/marshmallow/marshalling.py", line 295, in deserialize
index=(index if index_errors else None)
File "/python3.6/site-packages/marshmallow/marshalling.py", line 68, in call_and_store
value = getter_func(data)
File "/python3.6/site-packages/marshmallow/marshalling.py", line 288, in <lambda>
data
File "/python3.6/site-packages/umongo/abstract.py", line 127, in deserialize
return super().deserialize(value, attr=attr, data=data)
File "/python3.6/site-packages/marshmallow/fields.py", line 265, in deserialize
output = self._deserialize(value, attr, data)
File "/python3.6/site-packages/umongo/fields.py", line 437, in _deserialize
return self._deserialize_from_mongo(data)
File "/python3.6/site-packages/umongo/fields.py", line 447, in _deserialize_from_mongo
return self.embedded_document_cls.build_from_mongo(value)
File "/python3.6/site-packages/umongo/embedded_document.py", line 137, in build_from_mongo
doc.from_mongo(data)
File "/python3.6/site-packages/umongo/embedded_document.py", line 141, in from_mongo
self._data.from_mongo(data)
File "/python3.6/site-packages/umongo/data_proxy.py", line 66, in from_mongo
for k, v in data.items():
AttributeError: 'list' object has no attribute 'items'
500 POST / (127.0.0.1) 49.79ms
operating system name and version: ubuntu 17.10; python 3.6 my libs:
marshmallow==3.0.0b4
motor==1.1
pymongo==3.5.1
python-dateutil==2.6.1
tornado==4.5.2
umongo==0.15.0
with marshmallow==2.15.0 it raises too
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Hibernate: compare embedded field with an argument only if ...
I have an embedded field and I want to compare it to the passed parameter but only if this parameter is not null....
Read more >Using Djongo Model fields
Arguments. Field data integrity checks; Nesting Embedded Fields; Embedded Form; Querying Embedded fields; Using EmbeddedField in Django Admin; Data Model ...
Read more >Type Embedding - Go 101
From the article structs in Go, we know that a struct type can have many fields. Each field is composed of one field...
Read more >The Go Programming Language Specification
An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T , and...
Read more >Ethical Challenges of Embedded Experimentation
ignorance) that embedded field experiments do no harm are often not plausible. Not only do these ... This third argument is the most...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Don’t use
many
. Use aListField(EmbeddedField)
.Also (unrelated), don’t pass a mutable to
missing
or it will be shared with all objects (Python pitfall, nothing to do with umongo/Marshmallow). Marshmallow/umongo allows you to pass a callable, so you can writemissing=list
.Try this:
blueprints - here https://gist.github.com/malinich/d729b78f79a8a8c706812e10ebd5e25a