Skip to content
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

Default Factory management #453

Closed
bloodbare opened this issue Mar 25, 2019 · 4 comments
Closed

Default Factory management #453

bloodbare opened this issue Mar 25, 2019 · 4 comments
Assignees

Comments

@bloodbare
Copy link
Member

Default factory and default value on schema has some bugs:

  • Right now on behaviors, it's only taking care of missing_value attribute.
  • On context, it does not work properly (as sync/async factory)

In order to fix the issue I would like some feedback:

  • On a GET operation, the default value should not be committed and only serialized on JSON serializer module.

  • If we access the value on the code we should get the default value but add to the parent object if we are on a GET/HEAD operation.

@vangheem
Copy link
Member

This fixed part of it: #455

However, we still need to advise the usage of it with behaviors.

@jordic
Copy link
Contributor

jordic commented Mar 28, 2019

I just remember a bit the issue.. but it still feels a bit odd for me to return a default value on a GET operation (while this value is not present on the source state, db)... anyway I think it work for us.

@vangheem
Copy link
Member

@masipcat @jordic what is the status of this now? Can we close this you think?

@masipcat
Copy link
Contributor

masipcat commented Jun 21, 2019

I remember two issues related with defaults.

  • [SOLVED] Add key-value to schema.Dict fails silently #393
  • [UNSOLVED/UNREPORTED]: When using AnnotationBehaviors the default_factory defined in the field is ignored and I need to define the default_factory in the ContextProperty as well. Example:
class IImagesBehavior(Interface):

    index_field(
        "images",
        field_mapping={
            "type": "object",
            "enabled": False,  # index = False
            "properties": {},
        },
    )
    images = schema.Dict(
        key_type=schema.TextLine(),
        value_type=schema.TextLine(),
        required=False,
        default_factory=dict,
    #               -----^
    )


@configure.behavior(
    title="Images type map",
    provides=IImagesBehavior,
    marker=IImagesMarker,
    for_=IResource,
)
class ImagesBehavior(AnnotationBehavior):

    __local__properties__ = ("images",)

    images = ContextProperty("images", {})
    #                             -----^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants