Model Validation is not working as expected

Abierto
#512 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
18/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.9k
Forks
205
Merge medio
2 h 2 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de faust-streaming/faust

Todos los issues de faust-streaming/faust

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.