Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoided unnecessary recreation of RelatedObjects

Refs #19399. Thanks to Track alias KJ for the patch.
  • Loading branch information...
commit 3647c0a49a2f4535b8a9aba40e662743e4d53e76 1 parent 6158c79
@akaariai akaariai authored
View
5 django/core/management/validation.py
@@ -27,7 +27,6 @@ def get_validation_errors(outfile, app=None):
"""
from django.db import models, connection
from django.db.models.loading import get_app_errors
- from django.db.models.fields.related import RelatedObject
from django.db.models.deletion import SET_NULL, SET_DEFAULT
e = ModelErrorCollection(outfile)
@@ -154,7 +153,7 @@ def get_validation_errors(outfile, app=None):
e.add(opts, "Field '%s' under model '%s' must have a unique=True constraint." % (f.rel.field_name, f.rel.to.__name__))
rel_opts = f.rel.to._meta
- rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
+ rel_name = f.related.get_accessor_name()
rel_query_name = f.related_query_name()
if not f.rel.is_hidden():
for r in rel_opts.fields:
@@ -278,7 +277,7 @@ def get_validation_errors(outfile, app=None):
)
rel_opts = f.rel.to._meta
- rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
+ rel_name = f.related.get_accessor_name()
rel_query_name = f.related_query_name()
# If rel_name is none, there is no reverse accessor (this only
# occurs for symmetrical m2m relations to self). If this is the
View
9 django/db/models/options.py
@@ -4,7 +4,6 @@
from bisect import bisect
from django.conf import settings
-from django.db.models.related import RelatedObject
from django.db.models.fields.related import ManyToManyRel
from django.db.models.fields import AutoField, FieldDoesNotExist
from django.db.models.fields.proxy import OrderWrt
@@ -424,10 +423,10 @@ def _fill_related_objects_cache(self):
for f in klass._meta.local_fields:
if f.rel and not isinstance(f.rel.to, six.string_types):
if self == f.rel.to._meta:
- cache[RelatedObject(f.rel.to, klass, f)] = None
- proxy_cache[RelatedObject(f.rel.to, klass, f)] = None
+ cache[f.related] = None
+ proxy_cache[f.related] = None
elif self.concrete_model == f.rel.to._meta.concrete_model:
- proxy_cache[RelatedObject(f.rel.to, klass, f)] = None
+ proxy_cache[f.related] = None
self._related_objects_cache = cache
self._related_objects_proxy_cache = proxy_cache
@@ -468,7 +467,7 @@ def _fill_related_many_to_many_cache(self):
if (f.rel
and not isinstance(f.rel.to, six.string_types)
and self == f.rel.to._meta):
- cache[RelatedObject(f.rel.to, klass, f)] = None
+ cache[f.related] = None
if app_cache_ready():
self._related_many_to_many_cache = cache
return cache
View
3  django/forms/models.py
@@ -702,14 +702,11 @@ class BaseInlineFormSet(BaseModelFormSet):
"""A formset for child objects related to a parent."""
def __init__(self, data=None, files=None, instance=None,
save_as_new=False, prefix=None, queryset=None, **kwargs):
- from django.db.models.fields.related import RelatedObject
if instance is None:
self.instance = self.fk.rel.to()
else:
self.instance = instance
self.save_as_new = save_as_new
- # is there a better way to get the object descriptor?
- self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name()
if queryset is None:
queryset = self.model._default_manager
if self.instance.pk:
Please sign in to comment.
Something went wrong with that request. Please try again.