Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13516 closed (fixed)

sqlall silently ignores any fields that are a subclass of AutoField

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

Description

A field that is a subclass of AutoField will be silently ignored in the output of manage.py sqlall

An app with a models.py containing:

class MyAutoField(models.AutoField):
    pass

class TestModel(models.Model):
    id = MyAutoField(primary_key=True, db_column='SomeID')

will output the below from sqlall for sqlite3.

BEGIN;
CREATE TABLE "testapp_testmodel" (
)
;
COMMIT;

sqlall works as expected when models.AutoField is used instead of MyAutoField.

Attachments (1)

django-ticket13516-v1.2.diff (479 bytes) - added by manfre 5 years ago.
Fix Django 1.2 to allow subclassing AutoField

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by russellm

  • milestone 1.2 deleted
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from SVN to 1.1

Verified, but not 1.2 critical - this problem has existed for a while.

comment:2 Changed 5 years ago by manfre

  • Owner changed from nobody to manfre

Changed 5 years ago by manfre

Fix Django 1.2 to allow subclassing AutoField

comment:3 Changed 5 years ago by manfre

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

Added patch for Django v1.2 (up to r13444).

There is also the workaround of overriding get_internal_type in the subclass to return "AutoField" instead of self.class.name (from class Field). The issue is that the internal type is passed to the database backends so they can map the field to a database type.

class MyAutoField(models.AutoField):
    def get_internal_type(self):
        return "AutoField"

comment:4 Changed 5 years ago by manfre

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:5 Changed 5 years ago by manfre

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 5 years ago by russellm

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

(In [13540]) Fixed #13516 -- Added an internal type definition for AutoFields, so that subclassed fields are handled correctly by the SQL generator. Thanks to manfre for the report and patch.

comment:7 Changed 5 years ago by russellm

(In [13541]) [1.2.X] Fixed #13516 -- Added an internal type definition for AutoFields, so that subclassed fields are handled correctly by the SQL generator. Thanks to manfre for the report and patch.

Backport of r13540 from trunk.

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