mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.5.x] Fixed #19652 -- Fixed .none() regression in related fields
The regression was caused by using .none() when querying for related models, and the origin field's value was None. This resulted in missing custom related manager subclass as .none() returns plain QuerySet. This isn't backport from master, in master .none() correctly preserves the queryset's class. Patch provided by Simon Charette, with some minor polish by committer.
This commit is contained in:
@@ -498,7 +498,8 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||
db = self._db or router.db_for_read(self.model, instance=self.instance)
|
||||
qs = super(RelatedManager, self).get_query_set().using(db).filter(**self.core_filters)
|
||||
if getattr(self.instance, attname) is None:
|
||||
return qs.none()
|
||||
# We don't want to use qs.none() here, see #19652
|
||||
return qs.filter(pk__in=[])
|
||||
qs._known_related_objects = {rel_field: {self.instance.pk: self.instance}}
|
||||
return qs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user