Skip to content

Document.update doesn't allow updates with InnerDoc #1535

Closed
@kaiix

Description

@kaiix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions