Model Validation is not working as expected

未关闭
#512 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

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

调研方向

Start from the reproduction: a Record subclass with validation=True and a StringField(coerce=False) field, where non-string input is still accepted. Find where the model's validation and field coercion run, then check whether coerce=False is honored for str and whether numeric strings are coerced into float and int fields. The issue does not settle what the correct behavior is, so confirm the expected semantics with maintainers before changing anything.

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

描述

Steps to reproduce

class Metadata(Record, validation=True, serializer='json'):
  desc:str=StringField(coerce=False)
  lolo:Optional[float]
  low:Optional[float]
  high:Optional[float]
  hihi:Optional[float]
  units:Optional[str]
  prec:Optional[int]

then try to initialise an instance with anything other than a string for the desc field. I tried a different model, but it doesn't matter what you choose so long as it's not a string

Expected behavior

I would expect that anything other than a string would fail if coerce is set to False.
If coerce was set to True I would expect it to attempt to force the value to the required type and error if not possible.

Actual behavior

Any data type input into the desc field is accepted.
If you input a text string (i.e. not "3") into a float field, it is rejected as it's not the correct type, but "3" is, regardless of whether coerce is set to true or false.

If this isn't how it should be used, then I'll need to use another model/record system.

主要语言
Python
星标
1.9k
派生
205
平均合并
2 小时 2 分钟
30 天内合并 PR
1

环境准备

从这里开始

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

faust-streaming/faust 的其他 Issue

查看 faust-streaming/faust 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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