Skip to content

Commit

Permalink
Fixed full_hydrate so that readonly fields don't even attempt…
Browse files Browse the repository at this point in the history
… hydration. Thanks to mwtalbert for the report & testcase!
  • Loading branch information
toastdriven committed Jul 19, 2011
1 parent f2b37fc commit b183dd2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tastypie/resources.py
Expand Up @@ -673,6 +673,9 @@ def full_hydrate(self, bundle):
bundle.obj = self._meta.object_class()

for field_name, field_object in self.fields.items():
if field_object.readonly is True:
continue

if field_object.attribute:
value = field_object.hydrate(bundle)

Expand Down
4 changes: 4 additions & 0 deletions tests/core/models.py
Expand Up @@ -25,6 +25,10 @@ def what_time_is_it(self):
def get_absolute_url(self):
return '/some/fake/path/%s/' % self.pk

@property
def my_property(self):
return 'my_property'


class Subject(models.Model):
notes = models.ManyToManyField(Note, related_name='subjects')
Expand Down
1 change: 1 addition & 0 deletions tests/core/tests/resources.py
Expand Up @@ -756,6 +756,7 @@ class Meta:

class ReadOnlyRelatedNoteResource(ModelResource):
author = fields.ToOneField(UserResource, 'author', readonly=True)
my_property = fields.CharField(attribute='my_property', null=True, readonly=True)

class Meta:
queryset = Note.objects.all()
Expand Down

0 comments on commit b183dd2

Please sign in to comment.