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-filter custom field extensions do not allow for serializer fields #1007

Closed
realsuayip opened this issue Jun 18, 2023 · 0 comments
Closed
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@realsuayip
Copy link

Describe the bug

When specifying custom annotations for filters.Filter classes, only the basic types and raw openapi definitions are allowed:

if is_basic_type(annotation):
schema = build_basic_type(annotation)
else:
# allow injecting raw schema via @extend_schema_field decorator
schema = annotation.copy()

To Reproduce

from django_filters import rest_framework as filters

@extend_schema_field(serializers.CharField())
class CustomFilter(filters.Filter):
    field_class = django.forms.CharField

and use following filter in a view:

from django_filters import rest_framework as filters

class SomeFilter(filters.FilterSet):
    something = CustomFilter(required=True)
File "/usr/local/lib/python3.11/site-packages/drf_spectacular/contrib/django_filters.py", line 63, in get_schema_operation_parameters
result += self.resolve_filter_field(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/drf_spectacular/contrib/django_filters.py", line 100, in resolve_filter_field
schema = annotation.copy()
         ^^^^^^^^^^^^^^^
AttributeError: 'CharField' object has no attribute 'copy'

Expected behavior

I should be able to specify serializer fields in filter annotations.

@tfranzel tfranzel added enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Jun 19, 2023
tfranzel added a commit that referenced this issue Jun 19, 2023
fix functionality gap for decoration of django-filter fields #1007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 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