mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Raise warnings if 'request' not in context for hyperlinked fields.
This commit is contained in:
parent
388e617366
commit
41ac1e8f32
|
@ -311,6 +311,13 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
view_name = self.view_name
|
view_name = self.view_name
|
||||||
request = self.context.get('request', None)
|
request = self.context.get('request', None)
|
||||||
format = self.format or self.context.get('format', None)
|
format = self.format or self.context.get('format', None)
|
||||||
|
|
||||||
|
if request is None:
|
||||||
|
warnings.warn("Using `HyperlinkedRelatedField` without including the "
|
||||||
|
"request in the serializer context is due to be deprecated. "
|
||||||
|
"Add `context={'request': request}` when instantiating the serializer.",
|
||||||
|
PendingDeprecationWarning, stacklevel=4)
|
||||||
|
|
||||||
pk = getattr(obj, 'pk', None)
|
pk = getattr(obj, 'pk', None)
|
||||||
if pk is None:
|
if pk is None:
|
||||||
return
|
return
|
||||||
|
@ -420,6 +427,12 @@ class HyperlinkedIdentityField(Field):
|
||||||
view_name = self.view_name or self.parent.opts.view_name
|
view_name = self.view_name or self.parent.opts.view_name
|
||||||
kwargs = {self.pk_url_kwarg: obj.pk}
|
kwargs = {self.pk_url_kwarg: obj.pk}
|
||||||
|
|
||||||
|
if request is None:
|
||||||
|
warnings.warn("Using `HyperlinkedIdentityField` without including the "
|
||||||
|
"request in the serializer context is due to be deprecated. "
|
||||||
|
"Add `context={'request': request}` when instantiating the serializer.",
|
||||||
|
PendingDeprecationWarning, stacklevel=4)
|
||||||
|
|
||||||
# By default use whatever format is given for the current context
|
# By default use whatever format is given for the current context
|
||||||
# unless the target is a different type to the source.
|
# unless the target is a different type to the source.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue
Block a user