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

PATCH incorrectly normalizes default values in sub-documents #1234

Closed
zhangtemplar opened this Issue Mar 12, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@zhangtemplar
Copy link
Contributor

zhangtemplar commented Mar 12, 2019

Consider the following schema:

'entity': {
  'name': {
    'type': 'string',
    'required': True },
  'contact': {
    'type': 'dict',
    'required': True,
    'schema': {
      'phone': {
        'type': 'string',
        'required': False,
        'default': '1234567890' },
      'email': {
        'type': 'string',
        'required': False,
        'default': 'abc@efg.com' },
    }
  }
}

Assume I have data like:

{
  "name": "test",
  "contact: {
    "phone": "0987654321",
    "email": "uvw@xyz.com"
  }
}

When I do a patch with data {"contact.phone": "1111111111"} to update the phone only:

Expected behavior

The data will be changed to

{
  "name": "test",
  "contact: {
    "phone": "1111111111",
    "email": "uvw@xyz.com"
  }
}

Actual Behavior

But the data I get is:

{
  "name": "test",
  "contact: {
    "phone": "1111111111",
    "email": "abc@efg.com"
  }
}

Yes, the email is also changed: since email is not provided in PATCH body, its default value is used. Is it the intended behavior for eve?

Environment

  • Python version: 3.5.2
  • Eve version: 0.8.1
@zhangtemplar

This comment has been minimized.

Copy link
Contributor Author

zhangtemplar commented Mar 12, 2019

To resolve this problem, I think the solution would be changing the eve/validation.py's validate_update method and set normalize to be True.

    def validate_update(self, document, document_id, persisted_document=None):
        """ Validate method to be invoked when performing an update, not an
        insert.

        :param document: the document to be validated.
        :param document_id: the unique id of the document.
        :param persisted_document: the persisted document to be updated.
        """
        self.document_id = document_id
        self.persisted_document = persisted_document
        return super(Validator, self).validate(document, update=True, normalize=False)
@zhangtemplar

This comment has been minimized.

Copy link
Contributor Author

zhangtemplar commented Mar 12, 2019

@nicolaiarocci D1235 is ready.

@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Mar 28, 2019

@zhangtemplar see my comment in the PR

@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Apr 2, 2019

I reverted 9b2ba0f while we wait for a non-failing patch.

@nicolaiarocci nicolaiarocci reopened this Apr 2, 2019

@nicolaiarocci nicolaiarocci changed the title PATCH not working as expected for nested document PATCH incorrectly normalizes default values in subdocuments Apr 4, 2019

@nicolaiarocci nicolaiarocci changed the title PATCH incorrectly normalizes default values in subdocuments PATCH incorrectly normalizes default values in sub-documents Apr 4, 2019

nicolaiarocci added a commit that referenced this issue Apr 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.