ramses-tech / ramses

RAML + Elasticsearch / Postgres / Mongodb / Your Data Store™ + Pyramid = RESTful API
http://ramses.tech
Apache License 2.0
303 stars 29 forks source link

Nested endpoints at 4 levels behaving strangely with GET requests #90

Open adam-codeberg opened 9 years ago

adam-codeberg commented 9 years ago

Think there may be a similar matchdict problem with the AUTH procedure for GET requests for nested items at 4 levels.

A schema example can be found here https://github.com/adam-codeberg/ramses-templates/tree/master/memberships

For example, the API response forgets to include those nested items in the call back, despite _nested_depth:6 and the items can be accessed via a more direct call URL.

Included some info below.

GET :6543/api/contacts/1

    "orders": [
        {
            "_pk": "1", 
            "_type": "Order", 
            "_version": 0, 
            "contact": 1, 
            "fk_contact_id": 1, 
            "fk_product_id": "Top hits of 200BC", 
            "id": 1, 
            "payments": [], 
            "price_change": 0
        }
    ], 

x2 payments are missing.

GET :6543/api/contacts/1/orders

    "data": [
        {
            "_pk": "1", 
            "_score": 1.0, 
            "_self": "http://localhost:6543/api/contacts/1/orders/1", 
            "_type": "Order", 
            "_version": 0, 
            "contact": 1, 
            "fk_contact_id": 1, 
            "fk_product_id": "Top hits of 200BC", 
            "id": 1, 
            "payments": [
                {
                    "_pk": "1", 
                    "_type": "Payment", 
                    "_version": 0, 
                    "amount": "10", 
                    "fk_order_id": 1, 
                    "id": 1, 
                    "order": 1
                }, 
                {
                    "_pk": "2", 
                    "_type": "Payment", 
                    "_version": 0, 
                    "amount": "10", 
                    "fk_order_id": 1, 
                    "id": 2, 
                    "order": 1
                }
            ], 
            "price_change": 0
        }
    ], 

And calling the item at level 4 fails all together

GET :6543/api/contacts/1/orders/1

{
    "explanation": "The server could not comply with the request since it is either malformed or otherwise incorrect.", 
    "message": null, 
    "request_url": "http://localhost:6543/api/contacts/1/orders/1", 
    "status_code": 405, 
    "timestamp": "2015-10-20T11:23:36Z", 
    "title": "Method Not Allowed"
}

For now I've capped our JSON design at x3 levels, but would be nice to fix this at some point.

Heres the traceback

2015-10-20 22:27:32,267 DEBUG [txn.139968636479232][Dummy-3] _transaction.__init__: new transaction
2015-10-20 22:27:32,268 DEBUG [urllib3.util.retry][Dummy-3] retry.from_int: Converted retries value: False -> Retry(total=False, connect=None, read=None, redirect=0)
2015-10-20 22:27:32,269 DEBUG [urllib3.connectionpool][Dummy-3] connectionpool._make_request: "GET /licenseapi/Order/1/_source HTTP/1.1" 200 349
2015-10-20 22:27:32,269 INFO  [elasticsearch][Dummy-3] base.log_request_success: GET http://localhost:9200/licenseapi/Order/1/_source [status:200 request:0.001s]
2015-10-20 22:27:32,269 DEBUG [elasticsearch][Dummy-3] base.log_request_success: > None
2015-10-20 22:27:32,269 DEBUG [elasticsearch][Dummy-3] base.log_request_success: < {"price_change": 0, "_version": 0, "fk_product_id": "Top hits of 200BC", "_pk": "1", "contact": 1, "fk_contact_id": 1, "id": 1, "payments": [{"_type": "Payment", "fk_order_id": 1, "_version": 0, "order": 1, "amount": "10", "_pk": "1", "id": 1}, {"_type": "Payment", "fk_order_id": 1, "_version": 0, "order": 1, "amount": "10", "_pk": "2", "id": 2}]}
2015-10-20 22:27:32,270 DEBUG [nefertari_sqla.documents][Dummy-3] documents.get_collection: Get collection: AuthUser, {'username': u'system', '_item_request': True, '_limit': 1, '__raise_on_empty': True}
2015-10-20 22:27:32,277 DEBUG [nefertari_sqla.documents][Dummy-3] documents.get_collection: get_collection.query_set: AuthUser (SELECT ramses_authuser._version AS ramses_authuser__version, ramses_authuser.username AS ramses_authuser_username, ramses_authuser.email AS ramses_authuser_email, ramses_authuser.password AS ramses_authuser_password, ramses_authuser.groups AS ramses_authuser_groups FROM ramses_authuser WHERE ramses_authuser.username = %(username_1)s  LIMIT %(param_1)s OFFSET %(param_2)s)
2015-10-20 22:27:32,279 ERROR [nefertari.json_httpexceptions][Dummy-3] json_httpexceptions.create_json_response: 405 METHOD NOT ALLOWED: {"status_code": 405, "explanation": "The server could not comply with the request since it is either malformed or otherwise incorrect.", "message": null, "timestamp": "2015-10-20T11:27:32Z", "title": "Method Not Allowed"}
2015-10-20 22:27:32,279 DEBUG [txn.139968636479232][Dummy-3] _transaction.abort: abort
2015-10-20 22:27:32,280 ERROR [nefertari.json_httpexceptions][Dummy-3] json_httpexceptions.create_json_response: 405 METHOD NOT ALLOWED: {"request_url": "http://localhost:6543/api/contacts/1/orders/1", "timestamp": "2015-10-20T11:27:32Z", "title": "Method Not Allowed", "status_code": 405, "explanation": "The server could not comply with the request since it is either malformed or otherwise incorrect.", "message": null}
2015-10-20 22:27:32,280 DEBUG [nefertari.tweens][Dummy-3] tweens.timing: GET (http://localhost:6543/api/contacts/1/orders/1) request took 0.013090133667 seconds