A number that is not finite is stored as None at a field that accepts None

未关闭 适合新手
#140 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

issue 指向 ess/spec/request_types.py,具体是 inline,并说明请求验证测试已移至 request_types_test.py。先阅读 inline 和相关测试,然后运行该测试文件。如果字段接受 None 时非有限数会被拒绝(包括在组和列表中),且现有对 None 有效行为的测试仍然覆盖到,就算完成。

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

描述

bug

A number that is not finite is refused at a float field, because JSON holds it as null. At a field that also accepts None, it is stored as None and the request is accepted, so the workflow runs with None instead of the value given.

import math
from pathlib import Path
from pydantic import BaseModel
from ess.spec.request_types import held

class P(BaseModel):
    stop: float | None = None

class Q(BaseModel):
    stop: float = 1.0

files = lambda name, marker: name
local_path = lambda ref: Path('x')
held(P, 'stop', math.inf, files, local_path)  # (None, []): accepted, stored as None
held(Q, 'stop', math.inf, files, local_path)  # ParamsError: stop: has no JSON form that reads back as the value

The same holds inside groups and lists, at any field whose type accepts None.

Cause: request_types.inline checks that the stored JSON form reads back as itself (stored vs the JSON form of again), not that it reads back as the value given (made). inf becomes null in stored, null validates as None, and None has the JSON form null again, so the check passes.

Found while moving the request-validation tests to request_types_test.py.

主要语言
Python
星标
0
派生
0
平均合并
16 小时 17 分钟
30 天内合并 PR
56

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

scipp/essapps 的其他 Issue

查看 scipp/essapps 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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