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

Allow passing a schema class instead of schema instances #244

Open
sloria opened this issue Apr 2, 2019 · 5 comments
Open

Allow passing a schema class instead of schema instances #244

sloria opened this issue Apr 2, 2019 · 5 comments

Comments

@sloria
Copy link
Member

sloria commented Apr 2, 2019

Passing a schema instance makes it impossible to use schema context safely.

@taion
Copy link
Contributor

taion commented Apr 5, 2019

Somewhat related to #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?

@sloria
Copy link
Member Author

sloria commented Apr 5, 2019

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.

@itajaja
Copy link
Member

itajaja commented Apr 5, 2019

@sloria if multiple schemas need to be instantiated multiple times per-request, then they will have a separate context, so no problem there?

@sloria
Copy link
Member Author

sloria commented Apr 5, 2019

@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.

@taion
Copy link
Contributor

taion commented Apr 5, 2019

@itajaja is saying that if you have separate instances, then you would in fact be able to set context on them normally.

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

No branches or pull requests

3 participants