{"action":"created","issue":{"url":"https://api.github.com/repos/django-import-export/django-import-export/issues/493","repository_url":"https://api.github.com/repos/django-import-export/django-import-export","labels_url":"https://api.github.com/repos/django-import-export/django-import-export/issues/493/labels{/name}","comments_url":"https://api.github.com/repos/django-import-export/django-import-export/issues/493/comments","events_url":"https://api.github.com/repos/django-import-export/django-import-export/issues/493/events","html_url":"https://github.com/django-import-export/django-import-export/issues/493","id":165758871,"number":493,"title":"raise Error when model  has attribute __unicode__ which print some foreignKey value.","user":{"login":"GuihaiHU","id":3085435,"avatar_url":"https://avatars.githubusercontent.com/u/3085435?v=3","gravatar_id":"","url":"https://api.github.com/users/GuihaiHU","html_url":"https://github.com/GuihaiHU","followers_url":"https://api.github.com/users/GuihaiHU/followers","following_url":"https://api.github.com/users/GuihaiHU/following{/other_user}","gists_url":"https://api.github.com/users/GuihaiHU/gists{/gist_id}","starred_url":"https://api.github.com/users/GuihaiHU/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GuihaiHU/subscriptions","organizations_url":"https://api.github.com/users/GuihaiHU/orgs","repos_url":"https://api.github.com/users/GuihaiHU/repos","events_url":"https://api.github.com/users/GuihaiHU/events{/privacy}","received_events_url":"https://api.github.com/users/GuihaiHU/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-07-15T10:41:24Z","updated_at":"2016-07-21T16:36:02Z","closed_at":null,"body":"If A model has attribute `__unicode__`, foreignKey and print the foreignKey in `__unicode__`, when I import some new data, it will raise an Exception says `RelatedObjectDoesNotExist: XX has no yy.`\r\nFor example\r\n\r\n```python\r\n## models.py\r\ntitle = models.CharField(verbose_name=u'需求内容')\r\nproposer = models.ForeignKey(User, verbose_name=u'需求提出人', related_name='proposer')\r\n    def __unicode__(self):\r\n        return u'%s %s' % (self.proposer.username, self.title )\r\n```\r\n\r\n\r\n\r\nAfter reading the code in django-import-export, I found something wrong as follow:\r\n\r\n```python\r\n## resource.py\r\ninstance, new = self.get_or_init_instance(instance_loader, row)  # if row is new, will return an None instance\r\nrow_result.object_repr = force_text(instance) # try to get the foreignKey value, and raise Exception\r\n```"},"comment":{"url":"https://api.github.com/repos/django-import-export/django-import-export/issues/comments/234310421","html_url":"https://github.com/django-import-export/django-import-export/issues/493#issuecomment-234310421","issue_url":"https://api.github.com/repos/django-import-export/django-import-export/issues/493","id":234310421,"user":{"login":"JarnoRFB","id":8550270,"avatar_url":"https://avatars.githubusercontent.com/u/8550270?v=3","gravatar_id":"","url":"https://api.github.com/users/JarnoRFB","html_url":"https://github.com/JarnoRFB","followers_url":"https://api.github.com/users/JarnoRFB/followers","following_url":"https://api.github.com/users/JarnoRFB/following{/other_user}","gists_url":"https://api.github.com/users/JarnoRFB/gists{/gist_id}","starred_url":"https://api.github.com/users/JarnoRFB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JarnoRFB/subscriptions","organizations_url":"https://api.github.com/users/JarnoRFB/orgs","repos_url":"https://api.github.com/users/JarnoRFB/repos","events_url":"https://api.github.com/users/JarnoRFB/events{/privacy}","received_events_url":"https://api.github.com/users/JarnoRFB/received_events","type":"User","site_admin":false},"created_at":"2016-07-21T16:36:02Z","updated_at":"2016-07-21T16:36:02Z","body":"I think my proposal in #439 is pretty much bullshit. I thought if the models are first instantiated in the dry_run and saved only in the real import they would have the `related_model`, but isn't that what is already happening?\r\n Now I think just wrapping\r\n```python\r\nrow_result.object_repr = force_text(instance)\r\n```\r\nin a `try  - exept`  block would maybe do it. Or maybe the issue is with \r\n```python\r\ninstance, new = self.get_or_init_instance(instance_loader, row)\r\n``` \r\nreturning something strange for new rows as @GuihaiHU pointed out."}}
{"actor":{"display_login":"JarnoRFB"}}