Skip to content

PATCH incorrectly normalizes default values in sub-documents #1234

@zhangtemplar

Description

@zhangtemplar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions