3

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.

Community
  • 1
  • 1
acannon828
  • 528
  • 7
  • 22
  • What parameters would you need to pass? – 1.618 Apr 06 '15 at 20:20
  • Just updated my initial question with an explanation. – acannon828 Apr 06 '15 at 20:29
  • That sounds like a search query, which would mean the GET_MANY preprocessor would be used, even if you only expect one result. Can you post some of your actual code, and what you expect the requests to look like? – 1.618 Apr 06 '15 at 20:44
  • I was previously using GET_MANY, but things weren't working as expected. I just discovered this was due to my confusion regarding the [weird Python way in which arguments (e.g. `search_params`) are passed](http://www.jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/). – acannon828 Apr 06 '15 at 20:50

1 Answers1

1

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.

acannon828
  • 528
  • 7
  • 22