From 2f11cb6ffd875fc7b7684da04d62428343261552 Mon Sep 17 00:00:00 2001 From: Austin Matsick Date: Sun, 29 May 2016 14:05:45 -0500 Subject: [PATCH] #216 Specify `using` kwarg in get_real_instance method calls. --- polymorphic/models.py | 6 +++--- polymorphic/query.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/polymorphic/models.py b/polymorphic/models.py index 316267c..4674128 100644 --- a/polymorphic/models.py +++ b/polymorphic/models.py @@ -121,13 +121,13 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)): return model def get_real_concrete_instance_class_id(self, using=DEFAULT_DB_ALIAS): - model_class = self.get_real_instance_class() + model_class = self.get_real_instance_class(using=using) if model_class is None: return None return ContentType.objects.db_manager(using).get_for_model(model_class, for_concrete_model=True).pk def get_real_concrete_instance_class(self, using=DEFAULT_DB_ALIAS): - model_class = self.get_real_instance_class() + model_class = self.get_real_instance_class(using=using) if model_class is None: return None return ContentType.objects.db_manager(using).get_for_model(model_class, for_concrete_model=True).model_class() @@ -138,7 +138,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)): retrieve objects, then the complete object with it's real class/type and all fields may be retrieved with this method. Each method call executes one db query (if necessary).""" - real_model = self.get_real_instance_class() + real_model = self.get_real_instance_class(using=using) if real_model == self.__class__: return self return real_model.objects.db_manager(using).get(pk=self.pk) diff --git a/polymorphic/query.py b/polymorphic/query.py index a990e2c..1465e76 100644 --- a/polymorphic/query.py +++ b/polymorphic/query.py @@ -325,8 +325,8 @@ class PolymorphicQuerySet(QuerySet): results[base_object.pk] = base_object else: - real_concrete_class = base_object.get_real_instance_class() - real_concrete_class_id = base_object.get_real_concrete_instance_class_id() + real_concrete_class = base_object.get_real_instance_class(using=self._db) + real_concrete_class_id = base_object.get_real_concrete_instance_class_id(using=self._db) if real_concrete_class_id is None: # Dealing with a stale content type @@ -372,7 +372,7 @@ class PolymorphicQuerySet(QuerySet): for real_object in real_objects: o_pk = getattr(real_object, pk_name) - real_class = real_object.get_real_instance_class() + real_class = real_object.get_real_instance_class(using=self._db) # If the real class is a proxy, upcast it if real_class != real_concrete_class: