4

I am a new user of the Django Framework. I am currently building a REST API with the django_rest_framework. When starting my server I am getting deprecation warnings that I have no idea how to fix.

RemovedInDjango110Warning: 'get_all_related_objects is an unofficial API that has been deprecated. You may be able to replace it with 'get_fields()' for relation in opts.get_all_related_objects()

The above is the first of these. Does anyone know how to fix this issue. All I have in my API at the minute is standard rest calls using the built in ModelViewSet and I have also overwritten the default authentication & user system with my own so I have no idea why I'm getting these warnings as I have been using Django 1.9 from the start.

I also got this:

RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext

From my initial research this is related to templates. I am not using any templates so I don't know why this is coming up.

Can anyone help me to fix these issues?

wpercy
  • 9,636
  • 4
  • 33
  • 45
sgpbyrne
  • 565
  • 1
  • 7
  • 13
  • possible duplicate of http://stackoverflow.com/questions/29562070/how-to-suppress-the-deprecation-warnings-in-django ? – shmee Jan 25 '16 at 21:20
  • Is the version of the DRF you're using up to date? Best way to find them is to put a breakpoint on the line that creates the warning and then see the call stack – Sayse Jan 25 '16 at 21:43
  • I think you don't have to worry about this warnings, the authors of DRF wil fix them in the next update. – doru Jan 25 '16 at 21:46
  • Thanks for the replies! Yes I'm running off the latest DRF. I will just ignore them and wait for a fix in an update. I was just ensuring that I wasn't doing anything wrong. Thanks again – sgpbyrne Jan 25 '16 at 23:26

2 Answers2

7

In case someone lands here, regarding the second deprecation warning specifically:

RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext

This is only documented in the Django code:

def render(self, context=None, request=None):
    # A deprecation path is required here to cover the following usage:
    # >>> from django.template import Context
    # >>> from django.template.loader import get_template
    # >>> template = get_template('hello.html')
    # >>> template.render(Context({'name': 'world'}))
    # In Django 1.7 get_template() returned a django.template.Template.
    # In Django 1.8 it returns a django.template.backends.django.Template.
    # In Django 1.10 the isinstance checks should be removed. If passing a
    # Context or a RequestContext works by accident, it won't be an issue
    # per se, but it won't be officially supported either.

It can be easily fixed by removing the use of RequestContext or Context from render() and simply passing a dictionary.

Leaving it as is in v1.9 is not exactly the best thing to do. As Django devs suggest, it may or may not work well. The difference is that in 1.9 we get the deprecation warning.

Wtower
  • 18,848
  • 11
  • 103
  • 80
3

You don't have to "fix" Deprecation Warnings as they are, well, only warnings and things still work. However, if you'll decide to update they might break your app. So usually it's a good idea to rewrite the parts with warnings to new interfaces, that are hinted in those warnings if it's in your code. If it's in some side library you use, then you might want to wait if the library creator will update his/her library in the next release.

Regarding your particular warnings, unless you'll decide to update to Django 1.10, your code should work well.

Nikita
  • 6,101
  • 2
  • 26
  • 44