-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
CachedReferenceField creates DBRefs on to_python, but can't save them on to_mongo #1047
Comments
…f on to_python, but can't save them on to_mongo. Dereferencing DBRef to document type before returning it from to_python.
…ce_field_bugfix Suggested fix for #1047: CachedReferenceField DBRefs bug
Queryset evaluation performance for me after this change is horrendous, unfortunately... Item.objects.all() on 200 items with a few CachedReferenceFields apiece takes ~10 seconds to dereference everything before returning. It's not lazy, either, which makes this untenable for my uses at the moment. I'm not 100% sure what the original design of CachedReferenceField called for, but this works perfectly for my use case and is highly performant since it's using the cached values:
|
You're right @coffenbacher , we should add this. Are you or @amitlicht willing to submit a complementary PR? |
There are so many issues with CachedReferenceFields that it baffles me how it was put in the version to begin with. Basically unworkable, you can't fetch the object then save it without a validation error. You can't append a cachedreferencefield to a list without an attribute error. I would suggest to remove it entirely to not cause developers extra headache. |
I ended up abandoning CachedReferenceField and completing my project using a different approach, so unfortunately I'm not in a position to submit a PR on this one |
[Edited for unintentional tone in places and to split up certain parts into more relevant tickets.] In the process of executing on the Contentment ticket mentioned directly above I… accidentally my own ODM. A large piece to this was ensuring a) lazy transformation to native types with field data stored in the foreign representation for transformation-free direct use with PyMongo (you "pay" only for what you access, with no pre-caching of query sets, to-foreign transformations occur on assignment), and b) a viable cached reference field implementation usable as a projected instance of the referenced document without additional querying/dereferencing, allowing Trying to not spam alternative whole packages—that's lame—but I do want to offer an alternative approach to While the lazy access thing would require… some substantial refactoring in MongoEngine, a viable As a note, whole-document construction from MongoDB types generally must happen explicitly; automatic dereferencing/deserialization is largely a discouraged idea across Marrow Mongo, instead using Oh, yeah, model closures (a parent document class wholly containing related embedded document classes, with natural subclassing or overriding—Embeds referencing local attributes e.g. ".ClassName") are totally a thing, too, as best utilized in core by the Localized trait. But I digress. |
Since the initial bug of this ticket got fixed, I created another ticket to track this. I'm also not a big fan of CachedReferenceField... |
The text was updated successfully, but these errors were encountered: