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

TypeError: patched_resolve_filter_field() takes 5 positional arguments but 6 were given #295

Closed
adybionka opened this issue Feb 10, 2021 · 5 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@adybionka
Copy link

Describe the bug
After upgrading to 0.13.1 generating schema stopped working.

My djangorestframework version is 3.12.2

Traceback (most recent call last): File "./manage.py", line 44, in <module> execute_from_command_line(sys.argv) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/management/commands/spectacular.py", line 50, in handle schema = generator.get_schema(request=None, public=True) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/generators.py", line 219, in get_schema paths=self.parse(request, public), File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/generators.py", line 196, in parse operation = view.schema.get_operation(path, path_regex, method, self.registry) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/openapi.py", line 62, in get_operation parameters = self._get_parameters() File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/openapi.py", line 188, in _get_parameters **dict_helper(self._get_filter_parameters()), File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/openapi.py", line 355, in _get_filter_parameters parameters += filter_extension.get_schema_operation_parameters(self) File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/contrib/django_filters.py", line 44, in get_schema_operation_parameters return [ File "/Users/andrzejdybionka/.pyenv/versions/3.8.3/lib/python3.8/site-packages/drf_spectacular/contrib/django_filters.py", line 45, in <listcomp> self.resolve_filter_field(auto_schema, model, filterset_class, field_name, filter_field) TypeError: patched_resolve_filter_field() takes 5 positional arguments but 6 were given

To Reproduce
I just updated drf-spectacular to 0.13.1 and run ./manage.py spectacular. Downgrading to 0.13.0 solves this issue.

Expected behavior
Should generate the schema.

@tfranzel
Copy link
Owner

hi @adybionka, there has been a bugfix that required an internal interface change from

def resolve_filter_field(self, auto_schema, model, filterset_class, filter_field)

to

def resolve_filter_field(self, auto_schema, model, filterset_class, field_name, filter_field)

apparently you applied some custom patches with patched_resolve_filter_field. please adapt the call and it should work again.

@adybionka
Copy link
Author

You are right. Somebody in our project overwrote this function and I wasn't aware of it. And after digging in I see why:

In the resolve_filter_field function, there is line schema['enum'] = sorted(enum), which breaks generating schema in our project, because for some reason some of the enums contain None on the list, and the sorting function doesn't work due to this error TypeError: '<' not supported between instances of 'NoneType' and 'str'.

Is there any chance to handle this case in your lib to avoid overwriting this on our site?

@adybionka
Copy link
Author

Wow, thank you for the quick fix!

@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Feb 11, 2021
@adybionka
Copy link
Author

@tfranzel let me know when do you plan to release this fix.

I checked it locally and it works! Thank you one more time!

@tfranzel
Copy link
Owner

you're welcome. probably in 1-2 weeks given that we just released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants