Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Foo object at ...> is not JSON serializable #39

Open
thenewguy opened this issue Sep 29, 2015 · 1 comment
Open

<Foo object at ...> is not JSON serializable #39

thenewguy opened this issue Sep 29, 2015 · 1 comment

Comments

@thenewguy
Copy link

Model cluster does not support primary keys that are not of simple types.

If you have a primary key that uses something like this CashField from django's tests that doesn't inherit from one of the basic types known to the DjangoJSONEncoder then you get <Foo object at ...> is not JSON serializable.

The Cash object I linked to inherits from decimal.Decimal but that is because it is only a simple example for testing.

ModelCluster needs to do some sort of is_serializable check at https://github.com/torchbox/django-modelcluster/blob/c72110e7789415196336584c70b2706fe74dbc2d/modelcluster/models.py#L44 and use Field.value_to_string or the like if the object isn't serializable

@thenewguy
Copy link
Author

I just submitted a pull request. All tests pass for me locally. This issue isn't just for primary keys. That is just what I ran into first. It would be for any field that returns a value that cannot be directly converted to json. Not sure how you would want to test it. I can put together a quick test if you want with a custom field like the CashField in the django tests if you like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant