mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.5.x] Fixed empty strings + to_field regression on Oracle
Querying the reverse side of nullable to_field relation, where both
sides can contain null values resulted in incorrect results. The reason
was not detecting '' as NULL.
Refs #17541, backpatch of 09fcb70c80.
			
			
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| from operator import attrgetter | ||||
|  | ||||
| from django.db import connection, router | ||||
| from django.db import connection, connections, router | ||||
| from django.db.backends import util | ||||
| from django.db.models import signals, get_model | ||||
| from django.db.models.fields import (AutoField, Field, IntegerField, | ||||
| @@ -497,7 +497,8 @@ class ForeignRelatedObjectsDescriptor(object): | ||||
|                 except (AttributeError, KeyError): | ||||
|                     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: | ||||
|                     val = getattr(self.instance, attname) | ||||
|                     if val is None or val == '' and connections[db].features.interprets_empty_strings_as_nulls: | ||||
|                         # 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}} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user