Reputation: 538
GET_MANY preprocessors accept a built-in search_params
dictionary, but GET_SINGLE ones only accept instance_id
. A kw**
arg is passed to all pre and postprocessors, but I've found that this is just for forwards compatibility, though this is somewhat unclear in the Flask-Restless docs:
The arguments to the preprocessor and postprocessor functions will be provided as keyword arguments, so you should always add **kw as the final argument when defining a preprocessor or postprocessor function. This way, you can specify only the keyword arguments you need when defining your functions. Furthermore, if a new version of Flask-Restless changes the API, you can update Flask-Restless without breaking your code.
Is it then not possible to pass parameters other than instance_id
to a GET_SINGLE preprocessor?
EDIT
Perhaps there is a better way to do what I'm trying to do: I have two models, Foo
and Bar
. A record in Foo
stores as one of its columns a foreign key to a record in Bar
. I want a GET request sent to Foo
which specifies a value for the foreign key to return a single quasi-random record from the set of records in Foo
with a foreign key of the requested value.
Upvotes: 3
Views: 667
Reputation: 538
As @1.618 pointed out, my particular use case is better suited for a GET_MANY request, even if I'm only expected a single item in response. I'm still unsure of the answer to my initial question, but my intuition is that that no, there is not a way to pass params to a GET_SINGLE request, as in Flask-restless they are only intended for scenarios where an item is queried by id.
The solution to my particular problem was to use a GET_MANY request instead, which I had initially tried but couldn't get to work due to my incorrectly manipulating the search_params
argument and my confusion surrounding how variables are passed in Python.
Upvotes: 1