[Django] #29077: [Help] Why JSONField for MySql/MariaDB etc are not supported in Django?

11 views
Skip to first unread message

Django

unread,
Jan 27, 2018, 10:20:40 PM1/27/18
to django-...@googlegroups.com
#29077: [Help] Why JSONField for MySql/MariaDB etc are not supported in Django?
------------------------------------------+------------------------
Reporter: Akhil Lawrence | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords: help
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
JSON format is widely used these days. Databases like
[MariaDB](https://mariadb.com/kb/en/library/json-data-type/),
[MySql](https://dev.mysql.com/doc/refman/5.7/en/json.html) etc supports
JSONField. But within Django, JSONField is only provided for the postgres.
Why is it so? Is there any reason for this?

Also irrespective of whether the DB supports JSON datatype or not, JSON
can be implemented by modifying TextField. And it believe it is very
helpful. Why don't we simply provide it? Many programmers I know, do their
custom implementation of JSONField on almost all their projects.
Something like this,

{{{
class JSONField(models.TextField):
""" JSON field implementation on top of django textfield """

def to_dict(self, value):
""" convert json string to python dictionary """
return json.loads(value)

def to_json(self, value):
""" convert python dictionary to json string """
return json.dumps(value)

def from_db_value(self, value, expression, connection):
""" convert string from db to python dictionary """
if value is None:
return value
return self.to_dict(value)

def to_python(self, value):
""" convert model input value to python dictionary """
if isinstance(value, dict):
return value
if value is None:
return value
return self.to_dict(value)

def get_prep_value(self, value):
""" convert python dictionary to string before writing to db """
return self.to_json(value)
}}}


Could you guys please clarify Django teams perspective on this.

--
Ticket URL: <https://code.djangoproject.com/ticket/29077>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 29, 2018, 9:31:49 AM1/29/18
to django-...@googlegroups.com
#29077: [Help] Why JSONField for MySql/MariaDB etc are not supported in Django?
--------------------------------+--------------------------------------

Reporter: Akhil Lawrence | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution: invalid

Keywords: help | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Adding a database-agnostic JSONField was
[https://groups.google.com/d/topic/django-
developers/zfred27yVPg/discussion discussed on the mailing list]. Absent
that happening, [https://pypi.python.org/pypi/django-mysql django-mysql]
provides a `JSONField` for MySQL.

In the future, please see TicketClosingReasons/UseSupportChannels for ways
to find answers to "help" questions.

--
Ticket URL: <https://code.djangoproject.com/ticket/29077#comment:1>

Django

unread,
Oct 4, 2018, 3:13:07 AM10/4/18
to django-...@googlegroups.com
#29077: [Help] Why JSONField for MySql/MariaDB etc are not supported in Django?
--------------------------------+--------------------------------------

Reporter: Akhil Lawrence | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution: invalid

Keywords: help | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (by Carlton Gibson):

Proposal for cross DB JSONField #29821

--
Ticket URL: <https://code.djangoproject.com/ticket/29077#comment:2>

Reply all
Reply to author
Forward
0 new messages