Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30476 closed New feature (wontfix)

Add introspection of "json" (like "jsonb") data type as JSONField on PostgreSQL.

Reported by: Héctor Pablos Owned by:
Component: contrib.postgres Version: dev
Severity: Normal Keywords: inspectdb, JSONField, json, jsonb
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Héctor Pablos)

Right now, the inspectdb command, when the django.contrib.postgres app is added to INSTALLED_APPS in the settings, is able to detect jsonb fields and generate a model with the right django.contrib.postgres.fields.JSONField, but that's not the case for simple json fields.

The documentation states that the JSONField uses internally a PostgreSQL jsonb field, but I wonder if normal json fields could also be detected as a JSONField, as they can perfectly work for unmanaged models.

I'm happy to do a patch for this if it's considered necessary, adding an additional key to the ones provided by the contrib.postgres module inside the data_types_reverse dict with the following information:

114:  'django.contrib.postgres.fields.JSONField',

And the documentation and tests considered being necessary.

The id 114 is the OID of the json data type in PostgreSQL, at least in its 11.1 version. You can check this by executing the following query:

SELECT oid, typname
FROM pg_catalog.pg_type
WHERE typname='json';

Also happy to check other database versions if needed.

Change History (4)

comment:1 by Héctor Pablos, 6 years ago

Description: modified (diff)

comment:2 by Simon Charette, 6 years ago

There's enough significant differences between json and jsonb types which makes me believe this is not a good idea.

For example, containment operators it not supported on json columns while they are on jsonb ones which breaks the __contains lookup.

Version 1, edited 6 years ago by Simon Charette (previous) (next) (diff)

comment:3 by Mariusz Felisiak, 6 years ago

Resolution: wontfix
Status: newclosed
Summary: Add detection for PostgreSQL json field, aside from the already existing detection for jsonb field, using inspectdbAdd introspection of "json" (like "jsonb") data type as JSONField on PostgreSQL.
Version: 2.2master

Thanks for the report, however "json" data type would not be fully functional (especially in querying and indexing).

comment:4 by Adam Johnson, 6 years ago

Also worth bearing in mind is that there's a GSoC project underway to create a cross-DB JSONField, which ultimately inspectdb should probably point to https://summerofcode.withgoogle.com/organizations/5465143218012160/#projects

Note: See TracTickets for help on using tickets.
Back to Top