Closed mayteio closed 3 weeks ago
Mey @mayteio ,
Hrm, that's strange. Both this:
@strawberry_django.filter(models.Message, lookups=True)
class MessageFilter:
created_at: auto
Or this:
@strawberry_django.filter(models.Message)
class MessageFilter:
created_at: FilterLookup[datetime]
Should work. Both are also equivalent as auto
would translate to datetime
and lookups=True
would make it FilterLookup[datetime]
Do you have the full traceback of that? I'll try to investigate that later
@mayteio AHHH, taking a look at this again know I see what is going on... Note the message "Value cannot represent a DateTime: \"{'gt': '2023-12-21T22:26:06.691087'}\". ISO string too short"
This message is from dateutil.parser.isoparse
trying to parse the string "{'gt': '2023-12-21T22:26:06.691087'}" instead of
'2023-12-21T22:26:06.691087'`
That is happening because you defined the filter like:
@strawberry_django.filter(models.Message, lookups=True)
class MessageFilter:
created_at: datetime
The lookups=True
only have effect on auto
fields, what you type explicitally will be respected.
If you want the lookups you can either do created_at: bool
or, if you want to use datetime directly:
from strawberry_django.filters import FilterLookup
@strawberry_django.filter(models.Message, lookups=True)
class MessageFilter:
created_at: FilterLookup[datetime]
Let me know if that solves your issue
Thanks for the insight @bellini666! I will loop back to this soon 😄
Hey @mayteio ,
I'm considering that this has been solved for you? If not let me know so that we can reopen this
Describe the Bug
I'm trying to set up a simple paginated model that can filter based on the
created_at
field for a model like:Here's my custom resolver that filters messages based on the owner field and the authenticated user:
However, when I run the following query:
I get the following error:
It appears to me it's trying to parse the entire lookup filter as a datetime.
So if I instead annotate the filter directly using the
FilterLookup
type:I get the following error when running the same query:
I've searched the issues and docs and there are no examples of filtering by datetime. I guess I could roll this myself but I was wondering if it's possible to do within the scope of the strawberry-graphql-django 🙂
What am I doing wrong here?
Upvote & Fund