{"action":"created","issue":{"url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/19","repository_url":"https://api.github.com/repos/CodeYellowBV/django-binder","labels_url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/19/comments","events_url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/19/events","html_url":"https://github.com/CodeYellowBV/django-binder/issues/19","id":175517876,"number":19,"title":"RelatedObjectDoesNotExist error when saving a history-enabled model","user":{"login":"sjamaan","id":128536,"avatar_url":"https://avatars.githubusercontent.com/u/128536?v=3","gravatar_id":"","url":"https://api.github.com/users/sjamaan","html_url":"https://github.com/sjamaan","followers_url":"https://api.github.com/users/sjamaan/followers","following_url":"https://api.github.com/users/sjamaan/following{/other_user}","gists_url":"https://api.github.com/users/sjamaan/gists{/gist_id}","starred_url":"https://api.github.com/users/sjamaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjamaan/subscriptions","organizations_url":"https://api.github.com/users/sjamaan/orgs","repos_url":"https://api.github.com/users/sjamaan/repos","events_url":"https://api.github.com/users/sjamaan/events{/privacy}","received_events_url":"https://api.github.com/users/sjamaan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-07T14:31:00Z","updated_at":"2016-10-14T14:09:37Z","closed_at":"2016-10-14T14:09:37Z","body":"I have two Django models, `Shipment` and `SalesOrder`:\r\n\r\n```\r\nfrom django.db import models\r\nimport binder.models\r\nfrom binder.models import BinderModel\r\n\r\nclass Shipment(BinderModel):\r\n\tsales_order=models.OneToOneField('SalesOrder', on_delete=models.CASCADE, related_name='shipment')\r\n\r\n\tclass Binder:\r\n\t\thistory = True\r\n\r\nclass SalesOrder(BinderModel):\r\n\tclass Binder:\r\n\t\thistory = True\r\n```\r\n\r\nWhen I create a shipment and assign a pre-existing sales order to it, and then try to save the shipment, I get the exception: `django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist: SalesOrder has no shipment`.\r\n\r\nThis seems to be caused by the `elif` in `change` in `history.py`:\r\n\r\n```\r\n\tif hid in Transaction.changes:\r\n\t\told = Transaction.changes[hid][0]\r\n\telif old is DeferredM2M:\r\n\t\t# If we haven't seen this field before, and it's a m2m of\r\n\t\t# unknown value, we need to get the value now.\r\n\t\told = model(id=oid).binder_serialize_m2m_field(field)\r\n```\r\n\r\nThe `model(id=oid)` will instantiate a fresh, in-memory version of `SalesOrder`, which indeed has no shipment.  Then, it's serialized, and when the serialization code touches the `shipment` field, the exception happens."},"comment":{"url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/comments/253810665","html_url":"https://github.com/CodeYellowBV/django-binder/issues/19#issuecomment-253810665","issue_url":"https://api.github.com/repos/CodeYellowBV/django-binder/issues/19","id":253810665,"user":{"login":"sjamaan","id":128536,"avatar_url":"https://avatars.githubusercontent.com/u/128536?v=3","gravatar_id":"","url":"https://api.github.com/users/sjamaan","html_url":"https://github.com/sjamaan","followers_url":"https://api.github.com/users/sjamaan/followers","following_url":"https://api.github.com/users/sjamaan/following{/other_user}","gists_url":"https://api.github.com/users/sjamaan/gists{/gist_id}","starred_url":"https://api.github.com/users/sjamaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjamaan/subscriptions","organizations_url":"https://api.github.com/users/sjamaan/orgs","repos_url":"https://api.github.com/users/sjamaan/repos","events_url":"https://api.github.com/users/sjamaan/events{/privacy}","received_events_url":"https://api.github.com/users/sjamaan/received_events","type":"User","site_admin":false},"created_at":"2016-10-14T14:09:37Z","updated_at":"2016-10-14T14:09:37Z","body":"I can no longer reproduce this, so I'm assuming it's been fixed."}}
{"actor":{"display_login":"sjamaan"}}