{"action":"closed","issue":{"url":"https://api.github.com/repos/coleifer/peewee/issues/1082","repository_url":"https://api.github.com/repos/coleifer/peewee","labels_url":"https://api.github.com/repos/coleifer/peewee/issues/1082/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/peewee/issues/1082/comments","events_url":"https://api.github.com/repos/coleifer/peewee/issues/1082/events","html_url":"https://github.com/coleifer/peewee/issues/1082","id":180019458,"number":1082,"title":"Please provide a way to easily check NULLness of a foreign key field","user":{"login":"maaaks","id":3010238,"avatar_url":"https://avatars.githubusercontent.com/u/3010238?v=3","gravatar_id":"","url":"https://api.github.com/users/maaaks","html_url":"https://github.com/maaaks","followers_url":"https://api.github.com/users/maaaks/followers","following_url":"https://api.github.com/users/maaaks/following{/other_user}","gists_url":"https://api.github.com/users/maaaks/gists{/gist_id}","starred_url":"https://api.github.com/users/maaaks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maaaks/subscriptions","organizations_url":"https://api.github.com/users/maaaks/orgs","repos_url":"https://api.github.com/users/maaaks/repos","events_url":"https://api.github.com/users/maaaks/events{/privacy}","received_events_url":"https://api.github.com/users/maaaks/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-29T11:10:09Z","updated_at":"2016-09-29T13:57:03Z","closed_at":"2016-09-29T13:57:03Z","body":"Currently I know only two ways to check whether there is a related instance.\r\n\r\nFirst way:\r\n```python\r\ntry:\r\n    other_obj = obj.other_obj\r\n    # yes, there is\r\n\r\nexcept OtherObj.DoesNotExist:\r\n    # no, there isn't\r\n```\r\n\r\nThis is __too__ long for simple checks which I sometimes have to do.\r\n\r\nSecond way:\r\n```python\r\nif obj.other_obj_id:\r\n    # yes, there is\r\n```\r\n\r\nThis looks good and seems to work, but PyCharm highlights this as reference to a non-existing field `other_obj_id`, so I basically lose a lot of useful IDE features when using this undeclared attribute.\r\n\r\nIs there/will there be a third, convinient way to to this? Maybe something like this (I'm not sure how this can be implemented, just an idea):\r\n```python\r\nwith dont_throw_doesnotexist_here():\r\n    if obj.other_obj:\r\n        # yes, there is\r\n```\r\n\r\nOr, maybe:\r\n```python\r\nif SuppressDne(obj).other_obj:\r\n        # yes, there is\r\n```"}}
{"actor":{"display_login":"coleifer"}}