Code

Ticket #15146: patch.diff

File patch.diff, 926 bytes (added by elbarto, 3 years ago)
Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py  (revisión: 15343)
4+++ django/db/models/fields/related.py  (copia de trabajo)
5@@ -419,8 +419,12 @@
6 
7         class RelatedManager(superclass):
8             def get_query_set(self):
9-                db = self._db or router.db_for_read(rel_model, instance=instance)
10-                return superclass.get_query_set(self).using(db).filter(**(self.core_filters))
11+                if instance.pk is None:
12+                    query = superclass.get_empty_query_set(self)
13+                else:
14+                    db = self._db or router.db_for_read(rel_model, instance=instance)
15+                    query = superclass.get_query_set(self).using(db).filter(**(self.core_filters))
16+                return query
17 
18             def add(self, *objs):
19                 for obj in objs: