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

more contexts in pre/postprocessors #619

Open
tarekziade opened this issue Dec 24, 2016 · 4 comments
Open

more contexts in pre/postprocessors #619

tarekziade opened this issue Dec 24, 2016 · 4 comments

Comments

@tarekziade
Copy link
Contributor

It would be great to have more context when a pre/postprocessor function is called.

Having access to the model class, and other info parsed by the manager would be very useful.

my use case is to implement the If-Modified header so I need to query the model and check a requests header before allowing a data change.

Happy to build a PR for this if needed

@jfinkels
Copy link
Owner

Hi @tarekziade! This is probably a good idea. Access to the model class is an easy win. What other information might a preprocessor function need?

My concern is that after adding a new keyword argument for the preprocessor, (then another, then another...), we may end up with an unwieldy user interface. Perhaps it makes sense to collect the information into a single object, maybe a context dictionary or object, that has a key for each of the keyword arguments that the preprocessors currently accept. Then the preprocessor function just modifies the context in-place, and the Flask-Restless view function extracts the info it needs from the context object after the preprocessor returns. I think I should open a separate issue for that, however.

@tarekziade
Copy link
Contributor Author

What other information might a preprocessor function need?

Maybe the SA session and instance ?

maybe a context dictionary or object

Sounds like a good idea. Another option would be to pass the API instance directly maybe. Since it has all the mentioned info + more, like the primary_key etc

@tarekziade
Copy link
Contributor Author

@jfinkels One quick hack that does not require an API change is to add the API instance in flask.g

@tarekziade
Copy link
Contributor Author

This is my ugly and lame hack to make it work - I add in flask.g the api class :

https://github.com/mozilla/servicebook/blob/master/servicebook/server.py#L19

Then my postprocessor can implement the 412 & 428 :

https://github.com/mozilla/servicebook/blob/master/servicebook/server.py#L49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants