Closed ubaumann closed 4 years ago
@ubaumann could you add a test for your fix and ensure it fails if you revert your patch?
I can confirm this appears to fix https://github.com/dmkoch/django-jsonfield/issues/101. Without this change, JSON fields on parents don't get deserialized properly and are returned as strings instead.
The problem with this change is that id
is only the default primary key if none is specified, and this likely breaks deserialization when a primary key is explicitly specified. (see: https://docs.djangoproject.com/en/1.11/topics/db/models/#automatic-primary-key-fields)
@youssefm Thank you. I hadn't considered that.
@nemesisdesign I can add some test but it would add the dependency django-polymorphic
.
@nemesisdesign Should I add some tests? The fix is working well in our production environment.
I'm not a maintainer of this package, but unless django-polymorphic is too heavy, I would add it only as a dependency for the build. This kind of dependency is usually added in a file called requirements-test.txt
.
Alternatively it can be added directly here: https://github.com/dmkoch/django-jsonfield/blob/master/.travis.yml#L36
Hi All, my project depends on this PR, is there anything I can help with to get it merged?
Just my two cents here - the current fix may address the specific issue with django-polymorphic
, but I don't believe it fixes the more general problem that JSONField has, namely that a JSONField on a parent class gets deserialized as a string when an instance of the child class gets deserialized.
It seems to me that it would make more sense to fix the broader issue here rather than trying to detect instances of a particular library in order to treat them differently.
Hi all. I've added tests that ensure that jsonfield is compatible with MTI inheritance. If you have any further issues, please let me know. Thanks!
Fix polymorphic object issue: https://github.com/dmkoch/django-jsonfield/issues/101
With polymorphic objects I get a
AttributeError
onobj.pk
.obj.id
works fine.pk
andid
has in the tests always the same value.