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
ed65db36
Commit
ed65db36
authored
Aug 19, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3300 from jpadilla/listfield-child
Raise error when `source=` use on a child.
parents
dd850df1
8af366a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
rest_framework/fields.py
+12
-0
tests/test_fields.py
+18
-0
No files found.
rest_framework/fields.py
View file @
ed65db36
...
...
@@ -1381,7 +1381,13 @@ class ListField(Field):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
child
=
kwargs
.
pop
(
'child'
,
copy
.
deepcopy
(
self
.
child
))
self
.
allow_empty
=
kwargs
.
pop
(
'allow_empty'
,
True
)
assert
not
inspect
.
isclass
(
self
.
child
),
'`child` has not been instantiated.'
assert
self
.
child
.
source
is
None
,
(
"The `source` argument is not meaningful when applied to a `child=` field. "
"Remove `source=` from the field declaration."
)
super
(
ListField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
child
.
bind
(
field_name
=
''
,
parent
=
self
)
...
...
@@ -1424,7 +1430,13 @@ class DictField(Field):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
child
=
kwargs
.
pop
(
'child'
,
copy
.
deepcopy
(
self
.
child
))
assert
not
inspect
.
isclass
(
self
.
child
),
'`child` has not been instantiated.'
assert
self
.
child
.
source
is
None
,
(
"The `source` argument is not meaningful when applied to a `child=` field. "
"Remove `source=` from the field declaration."
)
super
(
DictField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
child
.
bind
(
field_name
=
''
,
parent
=
self
)
...
...
tests/test_fields.py
View file @
ed65db36
...
...
@@ -1416,6 +1416,15 @@ class TestListField(FieldValues):
]
field
=
serializers
.
ListField
(
child
=
serializers
.
IntegerField
())
def
test_no_source_on_child
(
self
):
with
pytest
.
raises
(
AssertionError
)
as
exc_info
:
serializers
.
ListField
(
child
=
serializers
.
IntegerField
(
source
=
'other'
))
assert
str
(
exc_info
.
value
)
==
(
"The `source` argument is not meaningful when applied to a `child=` field. "
"Remove `source=` from the field declaration."
)
class
TestEmptyListField
(
FieldValues
):
"""
...
...
@@ -1461,6 +1470,15 @@ class TestDictField(FieldValues):
]
field
=
serializers
.
DictField
(
child
=
serializers
.
CharField
())
def
test_no_source_on_child
(
self
):
with
pytest
.
raises
(
AssertionError
)
as
exc_info
:
serializers
.
DictField
(
child
=
serializers
.
CharField
(
source
=
'other'
))
assert
str
(
exc_info
.
value
)
==
(
"The `source` argument is not meaningful when applied to a `child=` field. "
"Remove `source=` from the field declaration."
)
class
TestUnvalidatedDictField
(
FieldValues
):
"""
...
...
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