Model Validation is not working as expected

オープン
#512 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

faust-streaming/faust のほかの issue

faust-streaming/faust の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。