Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
f07a4f4c
Commit
f07a4f4c
authored
Sep 20, 2013
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear cached serializer data on `save()` + test. Fixes #1116.
parent
eb0a98ad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
rest_framework/serializers.py
+3
-0
rest_framework/tests/test_serializer.py
+16
-0
No files found.
rest_framework/serializers.py
View file @
f07a4f4c
...
@@ -518,6 +518,9 @@ class BaseSerializer(WritableField):
...
@@ -518,6 +518,9 @@ class BaseSerializer(WritableField):
"""
"""
Save the deserialized object and return it.
Save the deserialized object and return it.
"""
"""
# Clear cached _data, which may be invalidated by `save()`
self
.
_data
=
None
if
isinstance
(
self
.
object
,
list
):
if
isinstance
(
self
.
object
,
list
):
[
self
.
save_object
(
item
,
**
kwargs
)
for
item
in
self
.
object
]
[
self
.
save_object
(
item
,
**
kwargs
)
for
item
in
self
.
object
]
...
...
rest_framework/tests/test_serializer.py
View file @
f07a4f4c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.db
import
models
from
django.db.models.fields
import
BLANK_CHOICE_DASH
from
django.db.models.fields
import
BLANK_CHOICE_DASH
...
@@ -136,6 +137,7 @@ class BasicTests(TestCase):
...
@@ -136,6 +137,7 @@ class BasicTests(TestCase):
'Happy new year!'
,
'Happy new year!'
,
datetime
.
datetime
(
2012
,
1
,
1
)
datetime
.
datetime
(
2012
,
1
,
1
)
)
)
self
.
actionitem
=
ActionItem
(
title
=
'Some to do item'
,)
self
.
data
=
{
self
.
data
=
{
'email'
:
'tom@example.com'
,
'email'
:
'tom@example.com'
,
'content'
:
'Happy new year!'
,
'content'
:
'Happy new year!'
,
...
@@ -264,6 +266,20 @@ class BasicTests(TestCase):
...
@@ -264,6 +266,20 @@ class BasicTests(TestCase):
"""
"""
self
.
assertRaises
(
AssertionError
,
PersonSerializerInvalidReadOnly
,
[])
self
.
assertRaises
(
AssertionError
,
PersonSerializerInvalidReadOnly
,
[])
def
test_serializer_data_is_cleared_on_save
(
self
):
"""
Check _data attribute is cleared on `save()`
Regression test for #1116
— id field is not populated is `data` is accessed prior to `save()`
"""
serializer
=
ActionItemSerializer
(
self
.
actionitem
)
self
.
assertIsNone
(
serializer
.
data
.
get
(
'id'
,
None
),
'New instance. `id` should not be set.'
)
serializer
.
save
()
self
.
assertIsNotNone
(
serializer
.
data
.
get
(
'id'
,
None
),
'Model is saved. `id` should be set.'
)
class
DictStyleSerializer
(
serializers
.
Serializer
):
class
DictStyleSerializer
(
serializers
.
Serializer
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment