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

Schema: object hierarchy #23

Closed
spiroid opened this issue Dec 5, 2014 · 3 comments
Closed

Schema: object hierarchy #23

spiroid opened this issue Dec 5, 2014 · 3 comments

Comments

@spiroid
Copy link
Contributor

spiroid commented Dec 5, 2014

Hi,

I have defined a schema in Eve to be used with a collection of products.
In this schema i added an 'images' attribute of type list of objects. It is expressed as follows :

    'name': {
        'type': 'string',
        'minlength': 3,
        'maxlength': 150,
        'required': True,
    },
    'images': {
        'type': 'list',
        'schema': {
            'type': 'dict',
            'schema': {
                'name': {
                    'type': 'string',
                    'required': True
                },
                'url': {
                    'type': 'string',
                    'required': True
                }
            }
        }
    },

This is a valid Cerberus format in Eve.
Inserting an object with a POST request works fine with a mongodb backend.

Request example:

POST on http://localhost:5000/products
with body containing :

{
  "name": "bird",
  "images": [{
    "name": "bird1",
    "url": "http://localhost/images/bird1.jpg"
  },
  {
    "name": "bird2",
    "url": "http://localhost/images/bird2.jpg"
  }]
}

With mongodb i receive a 201 response status whereas with elasticsearch i get a 500 response error and the data is not inserted nor the index created.

Am i missing something ?
Is any additional configuration required to make this work ?

Thanks

@spiroid
Copy link
Contributor Author

spiroid commented Dec 5, 2014

After investigation, it appears that this bug is not related to object hierarchies.
A simple example containing only the "name" attribute did not work.

The 500 error is raised by the python elastic search client. And more specificaly by the JSONSerializer that is broken in the 1.2.0 version.

I'm going to open an issue on ElasticSearch repository and propose a fix. Then i'll link that issue in this ticket.

Regards

spiroid added a commit to spiroid/eve-elastic that referenced this issue Dec 5, 2014
    revert to python 2 super() syntax in ElasticJSONSerializer
    'default' function

rel superdesk#23
@spiroid
Copy link
Contributor Author

spiroid commented Dec 5, 2014

A few more tests an a lot of coffee later, and i figured the issue was with eve-elastic json serializer and not with the elasticsearch one.

I opened a pull request with a fix : #24

@petrjasek
Copy link
Member

👍 thanks for that. released 0.2.3

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

2 participants