Opened 9 years ago

Last modified 8 months ago

#24928 new New feature

Add UUIDField, RangeField, JSONField, etc to database introspection

Reported by: Markus Holtermann Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Ülgen Sarıkavak Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

django.db.backends.postgresql_psycopg2.introspection.DatabaseIntrospection.data_types_reverse does not handle UUIDField and other core or contrib.postgres specific fields. And neither does any of the other backends.

Change History (15)

comment:1 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted
Type: BugNew feature

There's an interesting question about how contrib.postgres can "contribute" introspection rules to the postgres backend. Maybe the contrib.postgres fields should be handled in a separate ticket.

comment:2 by Claude Paroz, 9 years ago

IMHO, introspection should show the most accurate type, independently of the presence of contrib.postgres in the INSTALLED_APPS.

comment:3 by Tim Graham, 9 years ago

Claude, the issue in my mind is adding contrib references to django/db/backends/postgresql_psycopg2/introspection.py. If we allow contrib.postgres to play by special rules, that's not very friendly to third-party apps that might wish to add introspection for their own fields. But you have more experience in this area than I do, so please give your thoughts if you had ideas on how this should work.

comment:4 by Claude Paroz, 9 years ago

For me, this is not special rules, it's the rule "Django tries its best to introspect the database fields". If anyone want to provide contrib.mysql or contrib.oracle with custom fields, she's welcome to do so and we'll also be able to improve introspection for those backends.

Currently Django outputs models.TextField(blank=True, null=True) # This field type is a guess. for fields it doesn't know. Even if some field type is not implemented by Django models, we could imagine that we provide better hints (provided the type code is known), and point to popular third-party packages which implements those fields, inside comments.

comment:5 by Tim Graham, 9 years ago

What I envisioned for my proposal is a way for any app to contribute a mapping to a particular database backend's DatabaseIntrospection.data_types_reverse dictionary. I guess it might work something like south.modelsinspector.add_introspection_rules does, although I haven't looked at the implementation of that. Of course there's also the need to add the appropriate import in the models file that inspectdb generates since all fields won't be in django.db.models anymore.

comment:6 by Tim Graham, 8 years ago

Summary: Add UUIDField, RangeField, etc to database introspectionAdd UUIDField, RangeField, JSONField, etc to database introspection

comment:7 by Claude Paroz, 8 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned

comment:8 by Claude Paroz, 8 years ago

As UUIDField is a bit different (available in all backends with different implementation), I created a pull request just for that field.
A separate pull request will be proposed for other PostgreSQL-specific fields.

comment:9 by Claude Paroz, 8 years ago

Has patch: set

The "final" pull request, including the commit linked from the previous comment and the fix for #25454.

comment:10 by Claude Paroz <claude@…>, 8 years ago

In 3ea7167:

Refs #24928 -- Added introspection support for UUIDField

comment:11 by Claude Paroz <claude@…>, 7 years ago

In 0cbb6ac0:

Refs #24928 -- Added introspection support for PostgreSQL JSONField

Thanks Adam Johnson and Tim Graham for the reviews.

comment:12 by Claude Paroz <claude@…>, 7 years ago

In a599ae60:

Refs #24928 -- Added introspection support for PostgreSQL RangeField

comment:13 by Claude Paroz, 7 years ago

Patch needs improvement: set

HStoreField and ArrayField support still missing.

comment:14 by Mariusz Felisiak, 3 years ago

Owner: Claude Paroz removed
Status: assignednew

comment:15 by Ülgen Sarıkavak, 8 months ago

Cc: Ülgen Sarıkavak added
Note: See TracTickets for help on using tickets.
Back to Top