graphql-python / graphql-python/gql-next

Issues with DateTime ISO fields

未关闭
#29 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
78
派生
6
PR 合并指标
30 天内没有已合并 PR

描述

when i run `gql_run` and the `renderer_dataclasses.py` encounters a DateTime field it generates a field:

`var_name: datetime = None`

when I run a query that returns a datetime object I get the following error:

```
File "/Users/jasper/Documents/test/test-graph-python-client/env/lib/python3.7/site-packages/dataclasses_json/core.py", line 220, in _decode_generic
res = _get_type_cons(type_)(xs)
File "/Users/jasper/Documents/test/test-graph-python-client/env/lib/python3.7/site-packages/dataclasses_json/core.py", line 260, in
for x in xs)
File "/Users/jasper/Documents/test/test-graph-python-client/env/lib/python3.7/site-packages/dataclasses_json/core.py", line 165, in _decode_dataclass
infer_missing)
File "/Users/jasper/Documents/test/test-graph-python-client/env/lib/python3.7/site-packages/dataclasses_json/core.py", line 179, in _decode_dataclass
dt = datetime.fromtimestamp(field_value, tz=tz)
TypeError: an integer is required (got type str)
```

I think this is because in:
https://github.com/graphql-python/gql-next/blob/5c81e58862c8df3a335b81bb2f77a0fab2c50570/gql/renderer_dataclasses.py#L153-L160

`suffix` is being overwritten if the field is nullable and `DATETIME_FIELD` isn't being used.

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先检查 gql/renderer_dataclasses.py 第 153–160 行附近的代码,尤其是 nullable DateTime 字段如何处理 suffix,以及何时选择 DATETIME_FIELD。使用 DateTime 结果重现 gql_run 查询,并验证生成的 dataclass 能够在不出现所报告的 TypeError 的情况下反序列化返回的 ISO 值。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。