{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/283","labels_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/283/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/283/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/283/events","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/283","id":115055119,"number":283,"title":"Is there possibility to remove AttrDict-like magic wrappers?","user":{"login":"marcinn","id":139032,"avatar_url":"https://avatars.githubusercontent.com/u/139032?v=3","gravatar_id":"","url":"https://api.github.com/users/marcinn","html_url":"https://github.com/marcinn","followers_url":"https://api.github.com/users/marcinn/followers","following_url":"https://api.github.com/users/marcinn/following{/other_user}","gists_url":"https://api.github.com/users/marcinn/gists{/gist_id}","starred_url":"https://api.github.com/users/marcinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcinn/subscriptions","organizations_url":"https://api.github.com/users/marcinn/orgs","repos_url":"https://api.github.com/users/marcinn/repos","events_url":"https://api.github.com/users/marcinn/events{/privacy}","received_events_url":"https://api.github.com/users/marcinn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-11-04T13:50:26Z","updated_at":"2015-11-05T00:28:30Z","closed_at":null,"body":"I see strange behaviour:\r\n\r\n```\r\nfrom elasticsearch_dsl.utils import AttrDict\r\n\r\nclass MyObject(AttrDict):\r\n    def test(self):\r\n        self._d_ = 'something'\r\n````\r\n\r\nAnd test `_d_` replacement:\r\n\r\n```\r\nIn [11]: obj = MyObject({'a': 1, 'b': 2})\r\nIn [12]: obj._d_\r\nOut[12]: {'a': 1, 'b': 2}\r\n\r\nIn [13]: obj.test()\r\n\r\nIn [14]: obj._d_\r\nOut[14]: {'_d_': 'something', 'a': 1, 'b': 2}\r\n```\r\n\r\nThe `_d_` property is not overridden, but `something` is added as a new property.\r\nThis is very strange."},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/comments/153914667","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/283#issuecomment-153914667","issue_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/283","id":153914667,"user":{"login":"HonzaKral","id":32132,"avatar_url":"https://avatars.githubusercontent.com/u/32132?v=3","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":"2015-11-05T00:28:30Z","updated_at":"2015-11-05T00:28:30Z","body":"I will gladly drop any magic as long as we can still have attribute access (even for fields that are not defined) and automatic (de)serialization of `Object`, `Nested` and `Date` fields. What we can do here is to skip the 'magic' for protected attributes (with leading underscores) in the case of `DocType`, that would probably eliminate much of the pain.\r\n\r\nI do agree that magic is to be avoided, but in this case it is necessary, it is even the point of this library - to provide convenience. If you want the safe and explicit way, there is always `elasticsearch-py`. I would argue that the code written with the dsl is much simpler than any using the low-level client. I hold to the belief that it is the purpose of libraries, frameworks and other tools to make things easier for developers. In this case it means perhaps doing some magic so that the application code can be simple and explicit.\r\n\r\nIt is the same for other tools out there that they use (what some may call) anti-patterns to enable clean code for the users. Take a look at django models for example."}}