Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.9 deprecation warnings #3729

Closed
cnobile2012 opened this issue Dec 12, 2015 · 21 comments
Closed

Django 1.9 deprecation warnings #3729

cnobile2012 opened this issue Dec 12, 2015 · 21 comments
Labels
Milestone

Comments

@cnobile2012
Copy link

I realize you may not have gotten to these yet, but just in case you didn't know about them, there are new deprecation warning spit out when I ran my unit tests.

Using existing test database for alias 'default'...
/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:137: 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():

/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:149: RemovedInDjango110Warning: 'get_all_related_many_to_many_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_many_to_many_objects():

/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/renderers.py:676: RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.
  ret = template.render(context)
@xordoquy xordoquy changed the title Django 9 deprecation warnings Django 1.9 deprecation warnings Dec 14, 2015
@tomchristie tomchristie added this to the 3.3.3 Release milestone Dec 17, 2015
@tomchristie
Copy link
Member

Thanks for raising!

@kavirajk
Copy link

can anyone help me how to figure out list of all deprecated warnings so that we can change in corresponding files. I tried running tests with -r w option but it didn't help.

@xordoquy
Copy link
Collaborator

good question. @cnobile2012 any tip on how you got the warnings ?

@cnobile2012
Copy link
Author

Sorry guys, been real busy .

I have an old table that has issues which I'm in the process of fixing.
This is why I needed to run the tests with the -k. This may be the key to
getting the deprecations to show up also. You will see that there are also
issues with oauth2_provider. I've sent him a notice concerning this also.
Hope this helps.

$ ./manage.py test -k
/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/oauth2_provider/urls.py:10:
RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and
will be removed in Django 1.10. Update your urlpatterns to be a list of
django.conf.urls.url() instances instead.
url(r'^revoke_token/$', views.RevokeTokenView.as_view(),
name="revoke-token"),

/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/oauth2_provider/urls.py:20:
RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and
will be removed in Django 1.10. Update your urlpatterns to be a list of
django.conf.urls.url() instances instead.
url(r'^applications/(?P\d+)/update/$',
views.ApplicationUpdate.as_view(), name="update"),

Using existing test database for alias 'default'...
/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:137:
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():

/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:149:
RemovedInDjango110Warning: 'get_all_related_many_to_many_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_many_to_many_objects():

/home/cnobile/.virtualenvs/dinventory/local/lib/python2.7/site-packages/rest_framework/renderers.py:676:
RemovedInDjango110Warning: render() must be called with a dict, not a
RequestContext.
ret = template.render(context)

@kavirajk
Copy link

Thanks @cnobile2012. Let me cleanup these warnings.

@xordoquy is there any way to figure out all the deprecation warnings in the code base so that I will clean up all.? Or I should only follow up the release notes of django 1.9?

may I know how you guys got rid of deprecation warning for previous versions?

@aaugustin
Copy link
Contributor

Running DRF's tests (which I expect to be comprehensive) under -Werror will fail with a stack trace whenever they hit a deprecated code path in Django. This will tell you where warnings come from.

@tomchristie
Copy link
Member

@aaugustin - Indeed. Possible that we should be doing that as part of the standard travis runs.

@aaugustin
Copy link
Contributor

You may have to be smart and e.g. run with -Werroragainst Django 1.8 to find silent PendingDeprecationWarning which have become loud DeprecationWarning in 1.9.

Really it depends what level of warnings you have to tolerate to remain compatible with all version of Django you target. Once you make that decision, it makes sense to enforce it on the CI.

@kavirajk
Copy link

@aaugustin - Thanks. Good info

@kavirajk
Copy link

Sorry for late response.

I have run the drf tests with -Werror, and here is the following output

(drf)bash-4.3$ python -Werror runtests.py 
Traceback (most recent call last):
  File "runtests.py", line 8, in <module>
    import pytest
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/pytest.py", line 27, in <module>
    _preloadplugins() # to populate pytest.* namespace so help(pytest) works
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/_pytest/config.py", line 75, in _preloadplugins
    _preinit.append(get_config())
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/_pytest/config.py", line 84, in get_config
    pluginmanager.import_plugin(spec)
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/_pytest/config.py", line 384, in import_plugin
    __import__(importspec)
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/_pytest/main.py", line 6, in <module>
    import os, sys, imp
  File "/home/kaviraj/.virtualenvs/drf/lib/python3.5/imp.py", line 33, in <module>
    PendingDeprecationWarning, stacklevel=2)
PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

I think its problem with py.test deprication.

And here is the output of python -Wall runtests.py

(drf)bash-4.3$ python -Wall runtests.py 
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/_pytest/main.py:6: PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import os, sys, imp
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/coverage/__init__.py:46: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  args, varargs, kw, defaults = inspect.getargspec(meth)
/home/kaviraj/Documents/side_projects/django-rest-framework/rest_framework/authtoken/models.py:21: RemovedInDjango20Warning: on_delete will be a required arg for OneToOneField in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  user = models.OneToOneField(AUTH_USER_MODEL, related_name='auth_token')
/home/kaviraj/Documents/side_projects/django-rest-framework/tests/models.py:52: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  help_text='Target', verbose_name='Target')
/home/kaviraj/Documents/side_projects/django-rest-framework/tests/models.py:60: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  verbose_name='Optional target object')
/home/kaviraj/Documents/side_projects/django-rest-framework/tests/models.py:71: RemovedInDjango20Warning: on_delete will be a required arg for OneToOneField in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  related_name='nullable_source')
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/guardian/models.py:28: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  permission = models.ForeignKey(Permission)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/guardian/models.py:49: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  content_type = models.ForeignKey(ContentType)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/guardian/models.py:61: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  user = models.ForeignKey(user_model_label)
/home/kaviraj/.virtualenvs/drf/lib/python3.5/site-packages/guardian/models.py:79: RemovedInDjango20Warning: on_delete will be a required arg for ForeignKey in Django 2.0. Set it to models.CASCADE if you want to maintain the current default behavior. See https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ForeignKey.on_delete
  group = models.ForeignKey(Group)
================================================================ test session starts =================================================================
platform linux -- Python 3.5.0, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /home/kaviraj/Documents/side_projects/django-rest-framework, inifile: tox.ini
plugins: django-2.9.1, cov-1.8.1
collected 768 items 

tests/test_atomic_requests.py ....
tests/test_authentication.py ...............................
tests/test_bound_fields.py .......
tests/test_decorators.py ..........
tests/test_description.py ......
tests/test_fields.py ...........................................................................................................................................................................................................
tests/test_filters.py ........................
tests/test_generics.py ..........................
tests/test_htmlrenderer.py .....
tests/test_metadata.py .........
tests/test_middleware.py .
tests/test_model_serializer.py ......................................
tests/test_multitable_inheritance.py ...
tests/test_negotiation.py ...
tests/test_pagination.py ...........................
tests/test_parsers.py ......
tests/test_permissions.py ..........................
tests/test_relations.py ........................
tests/test_relations_generic.py ..
tests/test_relations_hyperlink.py .....................
tests/test_relations_pk.py .........................
tests/test_relations_slug.py ...............
tests/test_renderers.py ..............................
tests/test_request.py ................
tests/test_response.py ..................
tests/test_reverse.py ...
tests/test_routers.py ................
tests/test_serializer.py .....................
tests/test_serializer_bulk_update.py .....
tests/test_serializer_lists.py ...............
tests/test_serializer_nested.py .........
tests/test_settings.py ...
tests/test_status.py .
tests/test_templatetags.py ...
tests/test_testing.py ...............
tests/test_throttling.py ...............
tests/test_urlpatterns.py ....
tests/test_utils.py ............
tests/test_validation.py ..............
tests/test_validators.py ...................
tests/test_versioning.py ....................
tests/test_views.py ....
tests/test_viewsets.py ..
tests/browsable_api/test_browsable_api.py ......
tests/browsable_api/test_browsable_nested_api.py .

=================================================== 768 passed, 2 pytest-warnings in 7.28 seconds ====================================================
Running flake8 code linting
flake8 passed
Running isort code checking
Skipped 7 files
isort passed

This shows 2 pytest-warnings. So I executed py.test with -rw option. And here is the output

================================================================ test session starts =================================================================
platform linux -- Python 3.5.0, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /home/kaviraj/Documents/side_projects/django-rest-framework, inifile: tox.ini
plugins: django-2.9.1, cov-1.8.1
collected 768 items 

tests/test_atomic_requests.py ....
tests/test_authentication.py ...............................
tests/test_bound_fields.py .......
tests/test_decorators.py ..........
tests/test_description.py ......
tests/test_fields.py ...........................................................................................................................................................................................................
tests/test_filters.py ........................
tests/test_generics.py ..........................
tests/test_htmlrenderer.py .....
tests/test_metadata.py .........
tests/test_middleware.py .
tests/test_model_serializer.py ......................................
tests/test_multitable_inheritance.py ...
tests/test_negotiation.py ...
tests/test_pagination.py ...........................
tests/test_parsers.py ......
tests/test_permissions.py ..........................
tests/test_relations.py ........................
tests/test_relations_generic.py ..
tests/test_relations_hyperlink.py .....................
tests/test_relations_pk.py .........................
tests/test_relations_slug.py ...............
tests/test_renderers.py ..............................
tests/test_request.py ................
tests/test_response.py ..................
tests/test_reverse.py ...
tests/test_routers.py ................
tests/test_serializer.py .....................
tests/test_serializer_bulk_update.py .....
tests/test_serializer_lists.py ...............
tests/test_serializer_nested.py .........
tests/test_settings.py ...
tests/test_status.py .
tests/test_templatetags.py ...
tests/test_testing.py ...............
tests/test_throttling.py ...............
tests/test_urlpatterns.py ....
tests/test_utils.py ............
tests/test_validation.py ..............
tests/test_validators.py ...................
tests/test_versioning.py ....................
tests/test_views.py ....
tests/test_viewsets.py ..
tests/browsable_api/test_browsable_api.py ......
tests/browsable_api/test_browsable_nested_api.py .

=============================================================== pytest-warning summary ===============================================================
WC1 /home/kaviraj/Documents/side_projects/django-rest-framework/tests/test_model_serializer.py cannot collect test class 'TestMetaClassModel' because it has a __init__ constructor
WC1 /home/kaviraj/Documents/side_projects/django-rest-framework/tests/browsable_api/test_browsable_nested_api.py cannot collect test class 'TestNestedSerializerSerializer' because it has a __init__ constructor
=================================================== 768 passed, 2 pytest-warnings in 7.22 seconds ====================================================

And I think none of them shows any django 1.9 deprication problem in drf. What you guys think.. Am i missing something?

atombrella added a commit to atombrella/django-rest-framework that referenced this issue Jan 14, 2016
python -Werror generates warnings informing that on_delete is a required keyword in Django 2.0
xordoquy added a commit that referenced this issue Jan 14, 2016
@jplock
Copy link

jplock commented Jan 21, 2016

I've been running our tests with python -Wall manage.py test to see all of the deprecations. Would you welcome a pull request that works on addressing some of these? We have so many deprecation warnings in our logs its difficult to actually see the test failures, so I'm hoping this gets resolved in 3.3.3. :)

venv/local/lib/python2.7/site-packages/rest_framework/fields.py:1681: RemovedInDjango20Warning: `Field._get_val_from_obj` is deprecated, use `value_from_object` instead.
venv/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:110: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
venv/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py:110: RemovedInDjango20Warning: Usage of ForeignObjectRel.to attribute has been deprecated. Use the model attribute instead.

@xordoquy
Copy link
Collaborator

I'm a bit surprised we don't see them in our test suite.

@jplock
Copy link

jplock commented Jan 22, 2016

I'm using the django-nose test runner if that helps.

@xordoquy
Copy link
Collaborator

@jplock it's not about the test runner, it's about DRF test suite itself.

@jplock
Copy link

jplock commented Jan 22, 2016

Back to my original proposal though, would you welcome a pull request to try and address some of these? I wasn't sure if anyone else was looking into it or not.

@xordoquy
Copy link
Collaborator

@jplock will process it if we get something sure.

@ivan-klass
Copy link

Documentation at https://docs.djangoproject.com/en/1.9/ref/templates/api/# says nothing about using dictionary instead of Context/RequestContext objects :(

@xordoquy
Copy link
Collaborator

render isn't part of the template API.

@aaugustin
Copy link
Contributor

https://docs.djangoproject.com/en/1.9/topics/templates/#django.template.backends.base.Template.render says:

If context is provided, it must be a dict. If it isn’t provided, the engine will render the template with an empty context.

@ivan-klass
Copy link

@xordoquy @aaugustin, thank you for clarification!

@xordoquy xordoquy modified the milestones: 3.3.3 Release, 3.3.4 Release Feb 11, 2016
@xordoquy xordoquy modified the milestones: 3.3.4 Release, 3.4.0 Release Feb 12, 2016
@tomchristie
Copy link
Member

Believe these all to be resovled via #4158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants