mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
magic-removal: Modified caching strategy for descriptors to force re-evaluation of cache on the first get following a set. This is required to avoid duplication of the 'should I throw DoesNotExist' logic.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2598 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5072df1ac4
commit
d4a6375fba
@ -99,8 +99,11 @@ class SingleRelatedObjectDescriptor(object):
|
||||
# Set the value of the related field
|
||||
setattr(value, self.related.field.rel.get_related_field().attname, instance)
|
||||
|
||||
# Set the cache on the provided object to point to the new object
|
||||
setattr(value, self.related.field.get_cache_name(), instance)
|
||||
# Clear the cache, if it exists
|
||||
try:
|
||||
delattr(value, self.related.field.get_cache_name())
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
class ReverseSingleRelatedObjectDescriptor(object):
|
||||
# This class provides the functionality that makes the related-object
|
||||
@ -143,8 +146,11 @@ class ReverseSingleRelatedObjectDescriptor(object):
|
||||
val = None
|
||||
setattr(instance, self.field.attname, val)
|
||||
|
||||
# Set the cache to point to the new object
|
||||
setattr(instance, self.field.get_cache_name(), value)
|
||||
# Clear the cache, if it exists
|
||||
try:
|
||||
delattr(instance, self.field.get_cache_name())
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
class ForeignRelatedObjectsDescriptor(object):
|
||||
# This class provides the functionality that makes the related-object
|
||||
|
Loading…
x
Reference in New Issue
Block a user