elasticsearch-dsl-py icon indicating copy to clipboard operation
elasticsearch-dsl-py copied to clipboard

`Document.update` doesn't allow updates with `InnerDoc`

Open kaiix opened this issue 3 years ago • 0 comments

For example:

class Location(InnerDoc):
  country = Text()
  city = Text()
  
class User(Document):
  name = Text()
  location = Object(Location)

  class Index:
    ...

user = User(name='alice', location=Location(country='foo', city='bar'))
user.save()
user.update(location=Location(city='baz'))

then it will raise the following error

image

InnerDoc inherits from AttrDict, and merge method accepts AttrDict to be merged, the problem is that not all AttrDict subclasses implement a dict-like interface for iterate, such as InnerDoc

I think, its better to first convert AttrDict to dict in merge method to make it iterable. After this fix, doc creation & update can both accept InnerDoc.

kaiix avatar Sep 29 '21 07:09 kaiix