Skip to content

Commit

Permalink
Improved the way Model.save() skips the auto_field.
Browse files Browse the repository at this point in the history
Identity comparison is quicker than isinstance(), and it avoids coupling
between Model and AutoField.
  • Loading branch information
adamchainz authored and timgraham committed Nov 24, 2016
1 parent f095b24 commit 92bbef8
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions django/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from django.db.models import signals
from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import CASCADE, Collector
from django.db.models.fields import AutoField
from django.db.models.fields.related import (
ForeignObjectRel, OneToOneField, lazy_related_operation, resolve_relation,
)
Expand Down Expand Up @@ -899,7 +898,7 @@ def _save_table(self, raw=False, cls=None, force_insert=False,

fields = meta.local_concrete_fields
if not pk_set:
fields = [f for f in fields if not isinstance(f, AutoField)]
fields = [f for f in fields if f is not meta.auto_field]

update_pk = bool(meta.has_auto_field and not pk_set)
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
Expand Down

0 comments on commit 92bbef8

Please sign in to comment.