#23357 closed Bug (fixed)

MySQL DatabaseIntrospection.data_types_reverse for FIELD_TYPE.SHORT is wrong type

Reported by: jdufresne Owned by: nobody
Component: Database layer (models, ORM) Version: master
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 Changed 11 months ago by claudep

  • Cc introspection added
  • Component changed from Uncategorized to Database layer (models, ORM)
  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

Yes, and the same for FIELD_TYPE.TINY.

comment:2 follow-up: Changed 11 months ago by shaib

  • Cc introspection removed
  • Keywords introspection added

Is #22738 related?

comment:3 in reply to: ↑ 2 Changed 11 months ago by claudep

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 Changed 11 months ago by jdufresne

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 Changed 11 months ago by jdufresne

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

comment:6 Changed 11 months ago by jdufresne

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 additional comments, suggestions, or concerns. Thanks.

Last edited 11 months ago by jdufresne (previous) (diff)

comment:7 Changed 11 months ago by charettes

  • 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 Changed 11 months ago by jdufresne

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 Changed 11 months ago by charettes

  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:10 Changed 11 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from new to closed

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