#29963: JsonField should not allows top-level scalar values
----------------------------------+--------------------------------------
Reporter: Khashayar | Owner: nobody
Type: New feature | Status: closed
Component: contrib.postgres | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Simon Charette):
* status: new => closed
* resolution: => wontfix
* component: Database layer (models, ORM) => contrib.postgres
* version: 1.11 => master
* type: Bug => New feature
Comment:
Python integers that are serialized to JSON numbers [https://json.org/ are
valid JSON scalar values just like strings].
I assume you requesting that only JSON objects should be allowed to be
provided for top level values for `contrib.postgres.JsonField`. If that's
your request I'm afraid that it would be backward incompatible. It
shouldn't be too hard to subclass `JsonField` or provide
[https://docs.djangoproject.com/en/2.1/ref/validators/#module-
django.core.validators a validator] to prevent JSON scalar and array
equivalent values from being provided.
{{{#!python
def validate_dict(value):
if not isinstance(value, dict):
raise ValidatorError('...')
class Foo(models.Model):
data = JsonField(validators=[validate_dict])
}}}
I'll close this ticket as ''wontfix'' because of the backward
compatibility concerns and the small amount of code required to achieve it
using standard APIs. Feel free to re-open the ticket if I misunderstood
your request.
--
Ticket URL: <https://code.djangoproject.com/ticket/29963#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/074.2d2e073dc4d729ac79fa7aa12826dcff%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.