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
Fix embedded document inheritance #56
Conversation
Use _cls attribute when deserializing from DB
I'm still struggling with embedded document inheritance. I don't understand why your implementation calls When modifying them as I did (see new commit), I get both my use case and your tests to pass. I realize this is a pretty crappy bug report... It's still a bit blurry to me and I was not able to isolate a broken use case I could provide to illustrate the issue I had. If you're sure about your implementation, then there's definitely something I need to understand. Otherwise, I hope this will help. And I'm available to talk about it. |
Conflicts: umongo/fields.py
I just pushed an update to my workaround branch and I supposed you were notified, so I might as well comment on this. It is just a rebase to latest master. It is still hackish. Just a workaround that seems to work for me. Anyway the core issue (with failing test) is in #62. Unless I'm mistaken, this is a major fail in the |
e5cd0bb should have fixed this, thx for the work anyway 👍 |
I'm still having issues with this even with latest revision from master. I think it comes from the call to I really don't understand why we'd call The line before, data, errors = self.schema.load(value, partial=True) returns OO stuff. There can be Why not just call TheRightClassSelectedUsingCls(**data) (See updated branch. I can't reopen this PR and since it is closed, the new diff was not computed by GitHub.) If I get the time and manage to do it, I'll propose a failing test. |
Yes, please provide a testcase ^^ |
Reopening so that GitHub tracks my rebases and updates the diffs. Did you get any time to look into the test case I pushed (#67)? |
…doc_inheritance Conflicts: tests/test_fields.py umongo/fields.py
Fixed in #84. |
I'm afraid there's an issue with embedded document inheritance when deserializing from DB: the _cls attribute is ignored. Looks like it only works when loading from outside world, not from DB.
This dirty fix seems to do the trick in my use case, but it is certainly not the right implementation. It is mostly a copy-paste from
_deserialize
to_deserialize_from_mongo
. It should at least be factorized.I'm not sure the instance should be created using
to_use_cls(**value)
. It didn't work for me (complained about an unknown field name due to a dump_only field), so I randomly tried withbuild_from_mongo
and it happened to work...I think I had this case covered in my PR since I overrode
build_from_mongo
inEmbeddedDocumentImplementation
to pick the right class. But I'm not sure this is relevant to your implementation. I basically copied inheritance related stuff fromDocument
toEmbeddedDocument
, while you addressed inheritance inEmbeddedField
, AFAIU.BTW, isn't there a way in
EmbeddedField
to getembedded_document_cls
at init time (when declaring the field in the schema)?