CrossDB JSONField — Testing needed.

112 views
Skip to first unread message

Carlton Gibson

unread,
Jan 30, 2020, 9:46:47 AM1/30/20
to Django developers (Contributions to Django itself)
Hi all. 

From GSoC last year, Sage has a CrossDB JSONField for us: 


We still have a bit more close review to do but...


We need people to give it an outing, to find issues/regressions and so on. 


#### PostgreSQL:
Clone your DB etc. Change your Postgres JSONFields to the new `models.JSONField`, and so on. Create a migration. Migrate. Run your test suite. Did anything break? What wasn't clear from the docs?

#### Other Databases: 
Do you have some JSON handy? Create a new JSONField model. Give it a run. What doesn't work? 


If you could allocate a bit of time to try this out it would be a real help to make sure the new field is somewhat battle tested before bringing it in. 

The PR there is a fresh one just for this purpose. :)

Thanks all. 

Kind Regards,

Carlton

Message has been deleted
Message has been deleted

Jacob Rief

unread,
Feb 6, 2020, 1:35:09 AM2/6/20
to Django developers (Contributions to Django itself)
Hi Carlton, hi Sage,
I just tested this implementation against my JSONField form editor library, namely django-entangled, using SQLIte.
As you can see from the testing matrix, everything works fine using the well known jsonfield and jsonfield2, which until Django-3 are the only viable options currently available for SQLite.

However, after switching to the new implementation using the built-in JSONField, one of my units tests does not pass. After examining this locally, I discovered, that the form
reports product_form._errors: {'properties': ['Value must be valid JSON.']}
The location where this exception is raised, is inside the JSONField's validate() method. And the reason it is raised
is because json.dumps(value, cls=self.encoder) can not reparse a valid dictionary containing for instance a Python Decimal value.
Why should a valid Python dictionary be json.dumps(value, cls=self.encoder) anyway?

– Jacob

Adam Johnson

unread,
Feb 6, 2020, 4:09:18 AM2/6/20
to django-d...@googlegroups.com
Thanks for your testing!

It's being passed through json.dumps to check it would be possible to store it as JSON. Seems legitimate to me.

The other libraries default to an encoder that allows storage of Decimals, whilst the new field doesn't. Since Decimals don't round-trip in JSON (they're encoded as strings and then decoded back as strings), I think the new JSONField is making the right choice here.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/02f0df5e-3d9d-49c4-a81a-a1a2261a1b98%40googlegroups.com.


--
Adam

Jacob Rief

unread,
Feb 6, 2020, 10:12:05 AM2/6/20
to Django developers (Contributions to Django itself)
The reason it behaves differently to jsonfield and jsonfield2 is that it does not use the built-in django.core.serializers.json.DjangoJSONEncoder. Therefore serializing Decimal fields fails.
In my opinion the basic types, such as Decimal and Date/Time fields shall be serializable to JSON, but apparently there are different opinions out there.
Reply all
Reply to author
Forward
0 new messages