-
Notifications
You must be signed in to change notification settings - Fork 145
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
Polymorphism for schema #192
Comments
what do you guys think about this? |
@victorlin Can you provide a failing test case to solidify the idea? |
I really like this idea. I'm working on implementing a standard using JSON that does this very thing. It has one attribute that defines the type and the rest of the attributes can be validated depending on that "type" value. |
Great job @fangpenlin , I am surprised that the fix #192 has not been pull requested ? |
@antolantic there is no PR yet for the work @fangpenlin has done on her fork. |
@tseaver @antolantic Hi guys, I am not currently working on any project that's based on colander, and I don't have time to work on it now. You're very welcome to continue my previous work. |
Should I fork the @fangpenlin repo and make a PR then ? |
An administrative note: At the very least all of the commit authors need to have put their names into contributors.txt before anyone will consider merging such a PR into the official colander repo. |
@mmerickel I've added my name to contributors on top of my original branch does it help? |
@fangpenlin : could you initiate the PR ? |
A comment in Pylons#192 (comment) states that I should.
We have a scenario, say you have a message schema
For the payload, you can define it like this
It works fine if you can define all possible fields to the payload schema, however, in many cases, you simply can't. A better way is to define subclasses. Here we let Log inherits Payload
By doing that, when you do serializing or deserializing, the
payload = Payload()
is still there inMessageSchema
, so there is no way it can know which subclass schema to use. To solve that problem, we will need to have something like the polymorphism mechanism like the one from SQLAlchemy:http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#class-mapping-api
For colander, that could be something like
I will submit a pull request for this soon
The text was updated successfully, but these errors were encountered: