Model Validation is not working as expected

Đang mở
#512 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
1.9k
Fork
205
Merge trung bình
2 giờ 2 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của faust-streaming/faust

Tất cả issue của faust-streaming/faust

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.