jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.11k stars 348 forks source link

RemovedInDjango20Warning: field.rel -> field.remote_field #217

Closed mattayes closed 7 years ago

mattayes commented 7 years ago

You MUST use this template when reporting issues. Please make sure you follow the checklist and fill in all of the information sections below.


All versions of django-smart-selects prior to version 1.2.8 are vulnerable to an XSS attack as detailed in issue 171. As a result, all previous versions have been removed from PyPI to prevent users from installing insecure versions. All users are urged to upgrade as soon as possible.

Checklist

Put an x in the bracket when you have completed each task, like this: [x]

Steps to reproduce

  1. Set up the django-smart-selects test_app.
  2. Run python -Wd manage.py test.
  3. Look at stdout.

Actual behavior

Note: This is a subset of the warnings that are produced. I'll be opening other issues/PRs for the other deprecation warnings.

/path/to/django-smart-selects/smart_selects/db_fields.py:121: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  'queryset': self.rel.to._default_manager.complex_filter(

/path/to/django-smart-selects/smart_selects/db_fields.py:122: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  self.rel.limit_choices_to),

/path/to/django-smart-selects/smart_selects/utils.py:33: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  limit_choices_to = field.rel.limit_choices_to

/path/to/smart_selects/db_fields.py:231: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  'queryset': self.rel.to._default_manager.complex_filter(

/path/to/django-smart-selects/smart_selects/db_fields.py:232: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  self.rel.limit_choices_to),
/path/to/django-smart-selects/smart_selects/db_fields.py:233: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  'to_field_name': self.rel.field_name,

/path/to/django-smart-selects/smart_selects/db_fields.py:277: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  'queryset': self.rel.to._default_manager.complex_filter(

/path/to/django-smart-selects/smart_selects/db_fields.py:278: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  self.rel.limit_choices_to),

/path/to/django-smart-selects/smart_selects/db_fields.py:279: RemovedInDjango20Warning: Usage of field.rel has been deprecated. Use field.remote_field instead.
  'to_field_name': self.rel.field_name,

smart_selects/db_fields.py excerpts:

class ChainedManyToManyField(IntrospectiveFieldMixin, ManyToManyField):
    ...
    def formfield(self, **kwargs):
        ...
        defaults = {
            'form_class': form_fields.ChainedManyToManyField,
            'queryset': self.rel.to._default_manager.complex_filter(  # THIS SHOULD BE `self.remote_field...`
                self.rel.limit_choices_to),  # THIS SHOULD BE `self.remote_field.limit_choices_to`

Source

class ChainedForeignKey(IntrospectiveFieldMixin, ForeignKey):
    ...
    def formfield(self, **kwargs):
        ...
        defaults = {
            'form_class': form_fields.ChainedModelChoiceField,
            'queryset': self.rel.to._default_manager.complex_filter(  # THIS SHOULD BE `self.remote_field...`
                self.rel.limit_choices_to),  # THIS SHOULD BE `self.remote_field.limit_choices_to`
            'to_field_name': self.rel.field_name,  # THIS SHOULD BE `self.remote_field.field_name`

Source

class GroupedForeignKey(ForeignKey):
    ...
    def formfield(self, **kwargs):
        defaults = {
            'form_class': form_fields.GroupedModelSelect,
            'queryset': self.rel.to._default_manager.complex_filter(  # SHOULD BE `self.remote_field...`
                self.rel.limit_choices_to),  # SHOULD BE `self.remote_field.limit_choices_to`
            'to_field_name': self.rel.field_name,  # SHOULD BE `self.remote_field.field_name`

Source

smart_selects/utils.py excerpt:

def get_limit_choices_to(app_name, model_name, field_name):
    try:
        model = get_model(app_name, model_name)
        field = model._meta.get_field(field_name)
        limit_choices_to = field.rel.limit_choices_to  # THIS SHOULD BE field.remote_field.limit_choices_to

Source

Reference in Django 1.9 release notes

Expected behavior

Shouldn't see any warnings.

mattayes commented 7 years ago

Closing as the solution for handling Django 1.8 is clunky. Can re-open when Django 1.8 is no longer supported.