sssilver
sssilver

Reputation: 2859

search_params empty in a PATCH_MANY preprocessor in flask-restless

I have the following HTTP request issued via PUT:

http://example.com/api/student?q=%7B%22filters%22:%5B%7B%22name%22:%22id%22,%22op%22:%22%3D%3D%22,%22val%22:1%7D%5D,%22disjunction%22:true%7D

In which the query string decodes to:

q:{"filters":[{"name":"id","op":"==","val":1}],"disjunction":true}

In my flask-restless code, I create the endpoint with these options:

    {
        'model': Student,
        'methods': ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
        'preprocessors': {
            'POST': [pre_post_student],
            'PATCH_MANY': [pre_patch_many_student]
        },
        'allow_patch_many': True
    },

And then I have a preprocessor function defined:

def pre_patch_many_student(search_params=None, data=None, **kw):
    # Handle group management for the given students

    print search_params

However, when the function is called for the request above, search_params comes up as an empty dict.

Why?

Upvotes: 1

Views: 185

Answers (1)

Luis Orduz
Luis Orduz

Reputation: 2887

When patching, flask-restless doesn't look for the parameters in the url but rather as part of the body of the request. Thus the body should be:

{"q":{<filters and rules>},"field_to_edit":"content",...}

This might be too late already but anyways.

Upvotes: 2

Related Questions