Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#13516 closed (fixed)

sqlall silently ignores any fields that are a subclass of AutoField

Reported by: Michael Manfre Owned by: Michael 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 Michael Manfre 6 years ago.
Fix Django 1.2 to allow subclassing AutoField

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by Russell Keith-Magee

milestone: 1.2
Triage Stage: UnreviewedAccepted
Version: SVN1.1

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

comment:2 Changed 6 years ago by Michael Manfre

Owner: changed from nobody to Michael Manfre

Changed 6 years ago by Michael Manfre

Fix Django 1.2 to allow subclassing AutoField

comment:3 Changed 6 years ago by Michael Manfre

Has patch: set
Resolution: fixed
Status: newclosed

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 6 years ago by Michael Manfre

Resolution: fixed
Status: closedreopened

comment:5 Changed 6 years ago by Michael Manfre

Triage Stage: AcceptedReady for checkin

comment:6 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: reopenedclosed

(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 6 years ago by Russell Keith-Magee

(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