Error serializing field duration = models.DurationField()?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by running the supplied Asset model, AssetNode schema, and duration query against the listed environment to reproduce the error. Inspect graphql/type/scalars.py around line 51 and GraphQLScalarType around line 65, then verify that querying a non-null Django DurationField completes without the reported datetime.timedelta serialization error.
Written by the indexing model from the issue text.
Description
Hi there, i'm not 100% sure if this is a bug or not (I'm newbee here) but i got a problem while querying a Node that uses the field type models.DurationField ( it really returns datetime.timedelta).
Traceback (most recent call last):
File "/tmp/leaky_venv/lib/python3.6/site-packages/promise/promise.py", line 65, in try_catch
return (handler(*args, **kwargs), None)
File "/tmp/leaky_venv/lib/python3.6/site-packages/graphql/execution/executor.py", line 375, in <lambda>
resolved
File "/tmp/leaky_venv/lib/python3.6/site-packages/graphql/execution/executor.py", line 399, in complete_value
return complete_leaf_value(return_type, result)
File "/tmp/leaky_venv/lib/python3.6/site-packages/graphql/execution/executor.py", line 440, in complete_leaf_value
return return_type.serialize(result)
File "/tmp/leaky_venv/lib/python3.6/site-packages/graphql/type/scalars.py", line 51, in coerce_float
return float(value)
TypeError: float() argument must be a string or a number, not 'datetime.timedelta'
This error points to line 51 but i think the class GraphQLScalarType (on line 65) is also related.
Here is my env's prop
PostgreSQL 10.0 on x86_64-pc-linux-gnu (xubuntu 16.04), compiled by gcc (Debian 6.3.0-18) 6.3.0 20170516, 64-bit
Python == 3.6.1
Django==1.11.6
django-filter==1.1.0
graphene==2.0
graphene-django==2.0.0
graphql-core==2.0
graphql-relay==0.4.5
How to reproduce?
1- Create your model
class Asset(models.Model):
duration = models.DurationField(null=True, blank=True, help_text="Duration of a given offer/product (auto calculated)")
class Meta:
ordering = ["id"]
2-Create your schema
class AssetNode(DjangoObjectType):
class Meta:
model = Asset
interfaces = (relay.Node, )
3- insert a not-null value on the duration field... and run your query.
{assets(first:20,) {
edges {
node {
id
duration
}
}
}}
and you should que the error:
{
"message": "float() argument must be a string or a number, not 'datetime.timedelta'"
}
- Dominant language
- Python
- Stars
- 371
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphql-core-legacy
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Quiver source Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
graphql-python/graphql-core-legacy#286 · 3 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphql-core-legacy#280 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in graphql-python/graphql-core-legacy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·