flask-resty
flask-resty copied to clipboard
Allow passing a schema class instead of schema instances
Passing a schema instance makes it impossible to use schema context safely.
Somewhat related to https://github.com/4Catalyzer/flask-resty/issues/238.
I guess I was thinking that individual views might want to pass things into schema constructors, but that's never really happened.
Though, in practice, in a Flask context, wouldn't it be nearly equivalent to use flask.g instead of the schema context?
Hm, we could do what DRF does and allow either a schema_class class variable or a get_schema_instance method to be defined.
flask.g could work, though I'd worry if there are cases when schemas need to get instantiated multiple times per-request. Probably not an issue, though, considering we've been using instances this whole time.
@sloria if multiple schemas need to be instantiated multiple times per-request, then they will have a separate context, so no problem there?
@itajaja If you need a separate context per-instance, then flask.g could be problematic.
That said, I guess you could work around this by setting flask.g in pre_load and then resetting it in post_load.
@itajaja is saying that if you have separate instances, then you would in fact be able to set context on them normally.