{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/1075","repository_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py","labels_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/1075/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/1075/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/1075/events","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/1075","id":384538422,"node_id":"MDU6SXNzdWUzODQ1Mzg0MjI=","number":1075,"title":"How to call methods on Nested InnerDoc objects?","user":{"login":"annawinkler","id":3526523,"node_id":"MDQ6VXNlcjM1MjY1MjM=","avatar_url":"https://avatars3.githubusercontent.com/u/3526523?v=4","gravatar_id":"","url":"https://api.github.com/users/annawinkler","html_url":"https://github.com/annawinkler","followers_url":"https://api.github.com/users/annawinkler/followers","following_url":"https://api.github.com/users/annawinkler/following{/other_user}","gists_url":"https://api.github.com/users/annawinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/annawinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annawinkler/subscriptions","organizations_url":"https://api.github.com/users/annawinkler/orgs","repos_url":"https://api.github.com/users/annawinkler/repos","events_url":"https://api.github.com/users/annawinkler/events{/privacy}","received_events_url":"https://api.github.com/users/annawinkler/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-26T22:28:51Z","updated_at":"2018-12-03T17:41:05Z","closed_at":"2018-12-03T17:41:05Z","author_association":"CONTRIBUTOR","body":"I have a Document class with Nested objects, and I'd like to call validation methods on those Nested objects. What's the best way to do that? Here is a simple example that shows what I am trying to do:\r\n\r\n```\r\nclass AddressParts(InnerDoc):\r\n  house_number = Integer(required=True)\r\n  street_name = Keyword(required=True)\r\n  city_name = Keyword(required=True)\r\n\r\n  def validate(self):\r\n    if house_number < 0:\r\n\t  raise RuntimeError('Ooops this isn't a valid house number!')\r\n\r\nclass AddressData(InnerDoc):\r\n  address = Nested(AddressParts, required=True)\r\n  def validate(self):\r\n    address.validate()\r\n\r\nclass House(Document):\r\n  address_data = Nested(AddressData, required=True)\r\n\r\n  def validate(self):\r\n    address_data.validate()\r\n```\r\n\r\nBecause the fields are dicts, I then tried converting them to their objects like this:\r\n```\r\n  def validate(self):\r\n    AddressData(address_data.to_dict()).validate()\r\n```\r\nI get an error though `AttributeError: 'list' object has no attribute 'to_dict'` ... so I'm curious what the best approach is for what I'm trying to do?\r\n\r\nThanks!\r\nAnna\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/comments/443799675","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/1075#issuecomment-443799675","issue_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/1075","id":443799675,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Mzc5OTY3NQ==","user":{"login":"HonzaKral","id":32132,"node_id":"MDQ6VXNlcjMyMTMy","avatar_url":"https://avatars0.githubusercontent.com/u/32132?v=4","gravatar_id":"","url":"https://api.github.com/users/HonzaKral","html_url":"https://github.com/HonzaKral","followers_url":"https://api.github.com/users/HonzaKral/followers","following_url":"https://api.github.com/users/HonzaKral/following{/other_user}","gists_url":"https://api.github.com/users/HonzaKral/gists{/gist_id}","starred_url":"https://api.github.com/users/HonzaKral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HonzaKral/subscriptions","organizations_url":"https://api.github.com/users/HonzaKral/orgs","repos_url":"https://api.github.com/users/HonzaKral/repos","events_url":"https://api.github.com/users/HonzaKral/events{/privacy}","received_events_url":"https://api.github.com/users/HonzaKral/received_events","type":"User","site_admin":false},"created_at":"2018-12-03T17:41:05Z","updated_at":"2018-12-03T17:41:05Z","author_association":"MEMBER","body":"I created a PR in your repo which shows the API how it works in https://github.com/annawinkler/es_address_book/pull/1\r\n\r\nAlso note that `Nested` is meant to be used only when a `list` of objects is expected, if you expect to only have one `address` use `Object` instead and then you can skip the list in the example (just `House(address=AddressData(...))`)\r\n\r\nI also implemented a `clean` method which is a built-in (undocumented, my bad!) hook for users to add their own validation logic like you have done.\r\n\r\nHope this helps!"}}
{"actor":{"display_login":"HonzaKral"}}