Comments (5)
I'm also realizing that I might lack this feature when serializing data from Mongo world. It makes output a bit different depending on the path used (directly from DB or through OO world).
Mongo world is supposed to always return you the raw data, so there is no need to provide a custom get_attribute
. Thus Mongo world and OO world should provide the same consistent behavior (i.e. missing
is handled by marshmallow-pure schema)
Currently, schema_from_umongo_get_attribute is broken in Mongo world
As stated above: it is not broken, it is not needed 😄
Given your summarize, I think we agree missing_accessor
is doing more harm than good so I pushed a new version removing it. Beside, this feature should work with Mongo world as well as OO world, so open an issue if it's not the case 👍
from umongo.
Simple fix in as_marshmallow_schema
:
if missing_accessor and not mongo_world:
nmspc['get_attribute'] = schema_from_umongo_get_attribute
See master...Nobatek:dev_fix_mongo_world_missing_accessor
from umongo.
I'm wondering if we should not instead remove the missing_accessor
instead, then using only schema_from_umongo_get_attribute
when mongo_world
is False
.
This way the behavior should be the same than the direct access of de obj._data
field when mongo_world
is True
.
This would solve #74 as well ;-)
Do you think I missed a usecase with this ?
from umongo.
If you remove missing_accessor
parameter and consider not mongo_world
instead, you prevent the mongo_world is True and missing_accessor is True
case, which is right, at least as long as it is broken.
You also forbid the mongo_world is False and missing_accessor is False
case.
I'm not sure I get the whole picture about that schema_from_umongo_get_attribute
feature. From what I understand looking at the tests, its only use is to let the object return missing
and therefore remove the attribute from serialized data rather than returning None
. This is useful to me and I can remember myself complaining, when this feature was missing, about all the None
fields in my API output when data was missing in DB. I don't think of a use case where I would want to opt out, so I guess it is fine to not over-parametrize and just keep mongo_world
.
I'm also realizing that I might lack this feature when serializing data from Mongo world. It makes output a bit different depending on the path used (directly from DB or through OO world).
Currently, schema_from_umongo_get_attribute
is broken in Mongo world because it seeks the umongo schema and data proxy in the object. What if the umongo schema was stored somewhere in the marshmallow schema. Couldn't schema_from_umongo_get_attribute
figure out something with that schema and the raw data? This way, it could work in Mongo world as well, right?
To summarize, we have two independent points here:
-
Should and can that feature work in Mongo world? If some day the feature is extended to work in Mongo world, it will be a "breaking" change since it will slightly modify the output, but no big deal.
-
Should it be forced or parametrized? I'm not sure about the parameter. Today, I don't see the use case for opting out, but maybe someone would. I can't tell. If we keep the parameter, we just need to make sure the doc is clear about the implications. I must admit it's a bit blurry to me and I had to peek in the code and tests. For now, we might as well remove the parameter as it is broken anyway (#74). Let's not make things too complicated. If someone asks, it's never too late to put it back and fix its propagation.
from umongo.
OK, I get it. Removing it is the right thing to do.
Thanks.
from umongo.
Related Issues (20)
- How to reduce time when query doc from mongo with motor driver
- keyPattern not existing in DuplicteKeyError, causing `KeyError` HOT 3
- `find` with `GenericReferenceField` does not return the document.
- pymongo Database class explicitly denies bool HOT 3
- always $set usage with updating from commit
- Date serialization removes microseconds, but not during commit(), only when deserializing from mongo HOT 5
- 'id' based query other than of type ObjectId is returning None HOT 1
- Why does field.UUIDField return the same value for each instance? HOT 4
- Embedded document: unknown "fieldname" field in DB HOT 1
- DictFields and EmbeddedFields aren't created with default values HOT 4
- How to use UUID as _id HOT 3
- How do the isolation test
- Insert many documents at once
- ConstantField produces error when converting to marshmallow schema
- DictField with an EmbeddedDocument value produces error
- Referencing GridFS data?
- [RFC] Drop txmongo support? HOT 2
- Warning: The 'missing' attribute of fields is deprecated HOT 1
- Passing marshmallow Schema options to the models HOT 2
- Add commit_many() function to perform builk updates HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umongo.