Skip to content

Commit 13c1778

Browse files
ekaplan1bckohan
authored andcommitted
Improved support for accessing models when using multiple databases
1 parent 9fcebfe commit 13c1778

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/polymorphic/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def accessor_function(self):
207207
rel_obj = field.get_cached_value(self)
208208
except KeyError:
209209
objects = getattr(model, "_base_objects", model.objects)
210-
rel_obj = objects.get(pk=self.pk)
210+
rel_obj = objects.using(
211+
kwargs.get("using", self._state.db or DEFAULT_DB_ALIAS)
212+
).get(pk=self.pk)
211213
field.set_cached_value(self, rel_obj)
212214
return rel_obj
213215

0 commit comments

Comments
 (0)