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

Attempt to address Django 2.0 deprecate warnings related to field.rel #3906

Closed
wants to merge 3 commits into from

Conversation

jplock
Copy link

@jplock jplock commented Feb 5, 2016

This is related to django/django#4241

rest_framework/utils/model_meta.py:83: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  while pk.rel and pk.rel.parent_link:
rest_framework/utils/model_meta.py:92: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  for field in [field for field in opts.fields if field.serialize and not field.rel]:
rest_framework/utils/model_meta.py:107: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  for field in [field for field in opts.fields if field.serialize and field.rel]:
rest_framework/utils/model_meta.py:147: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  to_many=relation.field.rel.multiple,
rest_framework/utils/model_meta.py:163: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  (getattr(relation.field.rel, 'through', None) is not None) and
rest_framework/utils/model_meta.py:164: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  not relation.field.rel.through._meta.auto_created

I'm not sure how best to handle this for versions prior to Django 1.9

@xordoquy
Copy link
Collaborator

xordoquy commented Feb 6, 2016

Thanks for the PR. Unfortunately this breaks Django < 1.9 compatibility.
This can be solved with a compatibility function (compat.py) to handle the various cases.

@jplock
Copy link
Author

jplock commented Feb 6, 2016

@xordoquy thanks for the feedback, I added a compatibility function and the tests are now passing.

# If model is a child via multi-table inheritance, use parent's pk.
pk = pk.rel.to._meta.pk
pk = get_remote_field(pk).to._meta.pk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead have this set in a var after line 83? remote_field = get_remote_field(pk) and use throughout?

@tomchristie
Copy link
Member

Looks like this just needs bringing up to date with master.
Milestoning to keep it on my radar.

@tomchristie
Copy link
Member

Thanks for raising this @jplock. Now resolved!

@jplock
Copy link
Author

jplock commented Jun 2, 2016

Thanks for fixing this. Once I tried to implement @jpadilla's suggestion, I got stuck and distracted.

@jplock jplock deleted the jp-gh3729 branch June 2, 2016 13:48
@tomchristie
Copy link
Member

S'all good. We got there in the end!

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

Successfully merging this pull request may close these issues.

4 participants