{"action":"closed","issue":{"url":"https://api.github.com/repos/nshafer/django-hashid-field/issues/10","repository_url":"https://api.github.com/repos/nshafer/django-hashid-field","labels_url":"https://api.github.com/repos/nshafer/django-hashid-field/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/nshafer/django-hashid-field/issues/10/comments","events_url":"https://api.github.com/repos/nshafer/django-hashid-field/issues/10/events","html_url":"https://github.com/nshafer/django-hashid-field/issues/10","id":244160365,"number":10,"title":"TypeError when primary key is an OneToOneField","user":{"login":"OskarPersson","id":935414,"avatar_url":"https://avatars2.githubusercontent.com/u/935414?v=4","gravatar_id":"","url":"https://api.github.com/users/OskarPersson","html_url":"https://github.com/OskarPersson","followers_url":"https://api.github.com/users/OskarPersson/followers","following_url":"https://api.github.com/users/OskarPersson/following{/other_user}","gists_url":"https://api.github.com/users/OskarPersson/gists{/gist_id}","starred_url":"https://api.github.com/users/OskarPersson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OskarPersson/subscriptions","organizations_url":"https://api.github.com/users/OskarPersson/orgs","repos_url":"https://api.github.com/users/OskarPersson/repos","events_url":"https://api.github.com/users/OskarPersson/events{/privacy}","received_events_url":"https://api.github.com/users/OskarPersson/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"nshafer","id":3673047,"avatar_url":"https://avatars1.githubusercontent.com/u/3673047?v=4","gravatar_id":"","url":"https://api.github.com/users/nshafer","html_url":"https://github.com/nshafer","followers_url":"https://api.github.com/users/nshafer/followers","following_url":"https://api.github.com/users/nshafer/following{/other_user}","gists_url":"https://api.github.com/users/nshafer/gists{/gist_id}","starred_url":"https://api.github.com/users/nshafer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nshafer/subscriptions","organizations_url":"https://api.github.com/users/nshafer/orgs","repos_url":"https://api.github.com/users/nshafer/repos","events_url":"https://api.github.com/users/nshafer/events{/privacy}","received_events_url":"https://api.github.com/users/nshafer/received_events","type":"User","site_admin":false},"assignees":[{"login":"nshafer","id":3673047,"avatar_url":"https://avatars1.githubusercontent.com/u/3673047?v=4","gravatar_id":"","url":"https://api.github.com/users/nshafer","html_url":"https://github.com/nshafer","followers_url":"https://api.github.com/users/nshafer/followers","following_url":"https://api.github.com/users/nshafer/following{/other_user}","gists_url":"https://api.github.com/users/nshafer/gists{/gist_id}","starred_url":"https://api.github.com/users/nshafer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nshafer/subscriptions","organizations_url":"https://api.github.com/users/nshafer/orgs","repos_url":"https://api.github.com/users/nshafer/repos","events_url":"https://api.github.com/users/nshafer/events{/privacy}","received_events_url":"https://api.github.com/users/nshafer/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2017-07-19T20:14:18Z","updated_at":"2017-09-25T21:48:22Z","closed_at":"2017-09-25T21:48:22Z","author_association":"NONE","body":"With the models and serializers below I get an exception when listing the books:\r\n\r\n```\r\nTypeError: '1' value must be a valid Hashids string.\r\n```\r\n\r\nRemoving the nested serialization of authors in the book serialization gets rid of the exception but displays an invalid id for the author of each book.\r\n\r\n# Models\r\n\r\n```\r\n# books/models.py\r\nfrom django.db import models\r\nfrom hashid_field import HashidAutoField\r\n\r\nclass Book(models.Model):\r\n    id = HashidAutoField(primary_key=True)\r\n    name = models.CharField(max_length=255)\r\n    author = models.ForeignKey('authors.Author', on_delete=models.SET_NULL, related_name='books', null=True)\r\n```\r\n\r\n```\r\n# customauth/models.py\r\nfrom django.contrib.auth.models import AbstractUser\r\nfrom django.db import models\r\nfrom hashid_field import HashidAutoField\r\n\r\nclass User(AbstractUser):\r\n    id = HashidAutoField(primary_key=True)\r\n    created_at = models.DateTimeField(auto_now_add=True)\r\n    updated_at = models.DateTimeField(auto_now=True)\r\n```\r\n\r\n```\r\n# authors/models.py\r\n\r\nfrom django.conf import settings\r\nfrom django.db import models\r\n\r\nclass Author(models.Model):\r\n    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, primary_key=True)\r\n    description = models.TextField(max_length=1000)\r\n```\r\n\r\n# Serializers\r\n\r\n```\r\n# authors/serializers.py\r\nfrom django.conf import settings\r\nfrom django.contrib.auth import get_user_model\r\nfrom hashid_field.rest import HashidSerializerCharField\r\nfrom rest_framework import serializers\r\nfrom .models import Author\r\n\r\nclass UserSerializer(serializers.HyperlinkedModelSerializer):\r\n    id = HashidSerializerCharField(source_field='%s.id' % settings.AUTH_USER_MODEL)\r\n\r\n    class Meta:\r\n        model = get_user_model()\r\n        fields = ('url', 'id', 'username')\r\n\r\nclass AuthorSerializer(serializers.HyperlinkedModelSerializer):\r\n    user = UserSerializer()\r\n\r\n    class Meta:\r\n        model = Author\r\n        fields = ('url', 'user', 'description',)\r\n```\r\n\r\n```\r\n# books/serializers.py\r\nfrom hashid_field.rest import HashidSerializerCharField\r\nfrom rest_framework import serializers\r\nfrom authors.serializers import AuthorSerializer\r\nfrom .models import Book\r\n\r\nclass BookSerializer(serializers.HyperlinkedModelSerializer):\r\n    id = HashidSerializerCharField(source_field='books.Book.id')\r\n    author = AuthorSerializer()\r\n\r\n    class Meta:\r\n        model = Book\r\n        fields = ('url', 'id', 'name', 'author',)\r\n```"}}
{"actor":{"display_login":"nshafer"}}