Skip to content

Commit

Permalink
Cast every input to str
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielguarisa committed Oct 25, 2023
1 parent 016160b commit bb296a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "retrack"
version = "1.0.0-alpha.1"
version = "1.0.0-alpha.2"
description = "A business rules engine"
authors = ["Gabriel Guarisa <gabrielguarisa@gmail.com>", "Nathalia Trotte <nathaliatrotte@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion retrack/engine/request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __create_model(
fields = {}
for input_field in self.inputs:
fields[input_field.data.name] = (
str,
typing.Annotated[str, pydantic.BeforeValidator(str)],
pydantic.Field(
default=Ellipsis
if input_field.data.default is None
Expand Down
7 changes: 7 additions & 0 deletions tests/test_engine/test_request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ def test_validate_payload_with_valid_payload(valid_input_dict_before_validation)
assert isinstance(payload, pydantic.BaseModel)
result = rm.validate(pd.DataFrame([{"example": "test"}]))
assert isinstance(result, pd.DataFrame)


def test_validate_dict_with_model(valid_input_dict_before_validation):
rm = RequestManager([Input(**valid_input_dict_before_validation)])

assert issubclass(rm.model, pydantic.BaseModel)
assert rm.model.model_validate({"example": 1111}) == rm.model(example="1111")

0 comments on commit bb296a8

Please sign in to comment.