GithubHelp home page GithubHelp logo

Comments (5)

touilleMan avatar touilleMan commented on May 29, 2024 1

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.

lafrech avatar lafrech commented on May 29, 2024

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.

touilleMan avatar touilleMan commented on May 29, 2024

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.

lafrech avatar lafrech commented on May 29, 2024

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.

lafrech avatar lafrech commented on May 29, 2024

OK, I get it. Removing it is the right thing to do.

Thanks.

from umongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.