-
Notifications
You must be signed in to change notification settings - Fork 769
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
Converters cannot convert datetime.timedelta to float. #348
Comments
Yeah, I can see how that'd be a problem... Even if it could convert, a float doesn't quite capture all of the data in a timedelta. One possibility would be to add an ObjectType wrapper that pulls out the individual parts of the Any other ideas? |
I managed to get an human readlable for string type by using We probably won't need and human readable for the Float converter, so using timedelta.total_seconds() is fine... but, i think this works in py3 only |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is a bad bot. This is still an issue. |
Apologies @zeth , reopening the issue. If you have any time any help with the issue would be most appreciated. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Following |
Is help still wanted for this issue? I could give it a stab if yall can tell me what you want the solution to be? |
I used custom scalar for import datetime as dt
from graphene import Scalar
from graphql.language import ast
class DurationScalar(Scalar):
@staticmethod
def serialize(value):
if isinstance(value, dt.timedelta):
return str(value).zfill(8)[:-3]
@staticmethod
def parse_literal(node):
if isinstance(node, ast.StringValue):
delta = node.value.split(':')
duration = dt.timedelta(hours=delta[0], minutes=delta[1])
return duration
@staticmethod
def parse_value(value):
delta = value.split(':')
duration = dt.timedelta(hours=int(delta[0]), minutes=int(delta[1]))
return duration |
hello devs.
During a conversation about an issue of graphql-core @jkimbo found a possible error
graphene-django/graphene_django/converter.py
Lines 111 to 113 in 5051d3b
raising something like
{ "message": "float() argument must be a string or a number, not 'datetime.timedelta'" }
you can check graphql-python/graphql-core#150 for more info.
The text was updated successfully, but these errors were encountered: