Opened 15 years ago

Closed 14 years ago

Last modified 14 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: no UI/UX: no

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 14 years ago.
Fix Django 1.2 to allow subclassing AutoField

Download all attachments as: .zip

Change History (8)

comment:1 by Russell Keith-Magee, 15 years ago

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

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

comment:2 by Michael Manfre, 14 years ago

Owner: changed from nobody to Michael Manfre

by Michael Manfre, 14 years ago

Fix Django 1.2 to allow subclassing AutoField

comment:3 by Michael Manfre, 14 years ago

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

Resolution: fixed
Status: closedreopened

comment:5 by Michael Manfre, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Russell Keith-Magee, 14 years ago

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 by Russell Keith-Magee, 14 years ago

(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