Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid embedded document instance provided to an EmbeddedDocumentField #599

Closed
smileisak opened this issue May 31, 2016 · 0 comments
Closed

Comments

@smileisak
Copy link

Hi everyone,
I'm trying to create a code snippet to load some fixtures in mongomock via mongoengine.

products.json file:

{
  "products" :[
    {
      "ean": "328277917669",
      "name": "Product Added By Ismail",
      "family": "EMOLLIENTS & HYDRATANTS CORPS",
      "brand": "blabla",
      "assortment": "blabla",
      "area": "blaala",
      "tags": [
        {
          "name": "IDENTITE"
        }
      ]
    }]
}

Product Document and tag document:

class TagInstance(EmbeddedDocument):
    """
    This class represent an instance of the Tag used for defining product's rep's tags or conditions on questions
    values_ord is used to store values when an order is defined on values

    """
    # should be the same name of the tag
    name = StringField(required=False, max_length=200, null=True)
    # the comparator used for this tag instance
    comparator = StringField(required=False, max_length=200, null=True)
    # values of the tag inst could be one (=,<,>) or multiple values (Between, IN)
    # only one of this below fields should be used for a Tag
    values = ListField(StringField(required=False, max_length=200))
    values_ord = ListField(ListField(StringField(required=False, max_length=200), null=True))

class Product(DynamicDocument):
    """
    a class that represent a product
    """
    # Meta variables.
    meta = {'collection': 'products'}
    ean = StringField(required=False, max_length=200, null=True)
    name = StringField(required=False, max_length=200, null=True)
    family = StringField(required=False, max_length=200, null=True)
    brand = StringField(required=False, max_length=200, null=True)
    assortment = StringField(required=False, max_length=200, null=True)
    area = StringField(required=False, max_length=200, null=True)
    tags = ListField(EmbeddedDocumentField(TagInstance))

code snippet to load data to mongo passing by mongoengine:

def load_db_from_json_file(self):
        with open(self.fixtures_path + '/products.json') as data_file:
            data = json.load(data_file)
            for element in data.get('products'):
                product = Product(**element)
                product.save()

The error:
capture d ecran 2016-05-31 a 18 58 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant