Opened 10 years ago

Closed 10 years ago

#23357 closed Bug (fixed)

MySQL DatabaseIntrospection.data_types_reverse for FIELD_TYPE.SHORT is wrong type

Reported by: Jon Dufresne Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: introspection
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The MySQL backend maps a database field of type FIELD_TYPE.SHORT to IntegerField, but it seems to me that it should map to SmallIntegerField. The SmallIntegerField field class produces a smallint which eventually ends up as data type FIELD_TYPE.SHORT.

This can be found in file django/db/backends/mysql/introspection.py, class attribute DatabaseIntrospection.data_types_reverse[FIELD_TYPE.SHORT].

Contrast this with the file django/db/backends/mysql/creation.py, class attribute DatabaseCreation.data_types['SmallIntegerField'].

Change History (10)

comment:1 by Claude Paroz, 10 years ago

Cc: introspection added
Component: UncategorizedDatabase layer (models, ORM)
Easy pickings: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Yes, and the same for FIELD_TYPE.TINY.

comment:2 by Shai Berger, 10 years ago

Cc: introspection removed
Keywords: introspection added

Is #22738 related?

in reply to:  2 comment:3 by Claude Paroz, 10 years ago

Replying to shaib:

Is #22738 related?

Not really, as MySQL returns the same type_code=1 for both TINYINT and BOOLEAN. However, I just noticed that we might differentiate boolean fields on MySQL with internal_size/precision (4 for TINYINT and 1 for BOOLEAN).

comment:4 by Jon Dufresne, 10 years ago

I'd be happy to create and submit a patch that corrects the FIELD_TYPE.SHORT, but I'm not sure what should be done about FIELD_TYPE.TINY as that could theoretically represent either an int (of limited size) or a bool.

comment:5 by Jon Dufresne, 10 years ago

Pull request to handle SHORT: <https://github.com/django/django/pull/3117>

comment:6 by Jon Dufresne, 10 years ago

I updated the patch with the requested unit tests. I tested the unit tests using MySQL and sqlite. I do not have other database backends readily available to me.

Please let me know if there are any addition comments, suggestions, or concerns. Thanks.

Version 0, edited 10 years ago by Jon Dufresne (next)

comment:7 by Simon Charette, 10 years ago

Easy pickings: unset
Has patch: set
Patch needs improvement: set

This will require additional test adjustment and special casing for Oracle. Left comments on the PR.

comment:8 by Jon Dufresne, 10 years ago

This will require additional test adjustment and special casing for Oracle. Left comments on the PR.

Thanks for the comments. I updated the patch based on the feedback.

comment:9 by Simon Charette, 10 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:10 by Simon Charette <charette.s@…>, 10 years ago

Resolution: fixed
Status: newclosed

In f0d3dd4f04efa49e0b58da4847cb89770b59d4a8:

Fixed #23357 -- Added small int introspection support to MySQL backend.

In the MySQL backend, updated the can_introspect_small_integer feature
flag to True. In data_types_reverse, map FIELD_TYPE.SHORT to a
SmallIntegerField. Added test to verify introspecting SmallIntegerFields
and fixed existing tests influenced by this change.

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