Skip to content

Commit

Permalink
Merge pull request #3288 from thedrow/feature/cached-field-root-and-c…
Browse files Browse the repository at this point in the history
…ontext

Cached the field's root and context property
  • Loading branch information
tomchristie committed Aug 18, 2015
2 parents 1b53e80 + 7920058 commit bed3c45
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.utils import six, timezone
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.encoding import is_protected_type, smart_text
from django.utils.functional import cached_property
from django.utils.ipv6 import clean_ipv6_address
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -522,7 +523,7 @@ def fail(self, key, **kwargs):
message_string = msg.format(**kwargs)
raise ValidationError(message_string)

@property
@cached_property
def root(self):
"""
Returns the top-level serializer for this field.
Expand All @@ -532,7 +533,7 @@ def root(self):
root = root.parent
return root

@property
@cached_property
def context(self):
"""
Returns the context as passed to the root serializer on initialization.
Expand Down

0 comments on commit bed3c45

Please sign in to comment.