Skip to content

Django Model Filter not working (unexpected keyword argument '_get_id') #770

@cbergmiller

Description

@cbergmiller

Describe the Bug

I'm encountering a problem with the following use of strawberry_django.filter_type:

@strawberry_django.filter_type(SomeDjangoModel)
class SomeDjangoModelFilter:
    some_relation: auto

In my settings I have set DEFAULT_PK_FIELD_NAME to id.
When executing a query, I get this exception:

ERROR DjangoModelFilterInput.__init__() got an unexpected keyword argument '_get_id'

This seems to happen because the python_name of the strawberry field for the id field is not set in DjangoModelFilterInput. The name of the base resolver is then used for the ID-field, which is _get_id. I'm not sure why this is happening for me. Maybe I misconfigured something else?

When I add the following to strawberry_django/filters.py, the query is working:

@strawberry.input
class DjangoModelFilterInput:
    id: strawberry.ID

_DjangoModelFilterInput: Any = DjangoModelFilterInput

System Information

  • Operating system: Debian
  • Python version: 3.10.9
  • Strawberry version (if applicable): 0.275.5
  • Strawberry-django version: 0.62.0

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions