Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoEngine ListField within a EmbeddedDocument throws TypeError on validation

I am not sure if it is a bug within MongoEngine or if I miss something. I have the following Models set up:

class Features(EmbeddedDocument):
    version = FloatField()
    data = ListField(StringField)

class Article(Document):
    vendor = ReferenceField(Vendor)
    url = URLField()
    author = StringField()
    clean_content = StringField()
    features = EmbeddedDocumentField(Features)

When I test my models like this:

#add vendor
vendor = Vendor(name="techcrunch", config="vendor config")
vendor.save()

#create features
features = Features(version = 1.0)
features.data = ["5", "89"]

#add article
article = Article(vendor = vendor, url ="http://www.techcrunch.com", 
                  author ="MG Siegler", clean_content = "Apple rocks!")
article.features = features
article.save()

I get the following error:

TypeError: unbound method _validate() must be called with StringField instance as first argument (got str instance instead)

Can someone explain that?

EDIT:

Nevermind. I found my error.

It has to be:

class Features(EmbeddedDocument):
    version = FloatField()
    data = ListField(StringField())
like image 854
Karsten Avatar asked Sep 12 '12 16:09

Karsten


Video Answer


1 Answers

I found the error.

It has to be:

class Features(EmbeddedDocument):
    version = FloatField()
    data = ListField(StringField())
like image 143
Karsten Avatar answered Sep 22 '22 22:09

Karsten