-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add Meta option to include non init-ed fields #246
Conversation
9af39bb
to
000aa58
Compare
@lovasoa the tests appear to also be broken on master due to bitrot, have fixed those. |
000aa58
to
7b8ed2b
Compare
Have pushed a better fix for the mypy test failure |
Thanks for the cleanup ! |
Last failing test seems to be some ordering thing that I have no idea how to fix 😬 |
I've just pushed a commit that refactors It could probably use a little more cleanup and review. (E.g. to make sure I haven't inadvertently made the check too lenient.) |
The problem was with the order of union fields. But are you sure we don't care about it? If there is a logic of "first field that works", then it won't behave the same. |
You're right, of course. Crap. (Though I still think the rest of the refactor to |
I was writing a comment about comparing the values to themselves, but I see you realized it yourself. But the point is: it's much more complicated and error prone that way. Can we go back to just the reprs ? It was very simple and worked well. If it's not broken, don't fix it 😛 |
ddd3428
to
0fa65f5
Compare
Here's the issue with the Union field ordering. (I think.) It has to do with the fact that
The failure of our [test_optional_multiple_types] is exercised by this change in The cause of all this is that, while our I'm not sure what the fix is. |
0fa65f5
to
d9bf221
Compare
Wow, that is strange ! If there is really no way to extract the original order of the union members, then we don't have any choice but to special-case our tests to allow any order for the members of |
ecca736
to
d9bf221
Compare
Ok, thanks to both of you. I'm going to release a new version |
But the tests Here's a clearer explanation of what's going on...
But, even though they are different instances, So Brainstorming... Maybe we could implement our own custom union type that would bypass We could maybe somehow monkeypatch |
You are right ! You can make such a patch, but personally, I'd just wait to see if anyone needs it. This theoretically can be a problem, but I'm not sure a fix is urgently needed |
@lovasoa The Union type ordering issue has nothing to do with the original point of the PR, so I don't object to making a release to get the But, our handling of union types is quite broken. (And I think it always has been?) The tests were correct in checking the order of Here's a simple demo to illustrate the issue. (Put this in from typing import Optional, Union
from marshmallow_dataclass import dataclass
# Comment out the next line and the assert will pass, otherwise it will fail
Optional[Union[str, int]]
@dataclass
class Test:
x: Optional[Union[int, str]]
assert Test.Schema().load({"x": "42"}) == Test(x=42) |
I agree we should create an issue and document the current clunky behavior, but I don't think we should re-break the tests on master |
The failing tests could be marked xfail |
don't you think it's better to still test that the union members are all here and correct than giving up on testing union altogether ? |
We could do both. Mark the existing failing tests as expected failures. Add a new test (or tests) to check things that currently work that were checked by the failing tests. I think the xfail tests are important as reminders of what is broken. Since we know there's a problem, there should be a test that exercises it. |
Good, I'm fine with that ! |
Updates #60
This adds the ability to include non init-ed fields into the schema by using a new Meta option ,
include_non_init
.I don't think it's the best way to address #60, but it is a very small code change to get the functionality working.