Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Various fixes for Open API #3947

Merged
5 commits merged into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/verta/tests/registry/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def docker_image():

@pytest.fixture
def make_model_schema_file(tmp_path, monkeypatch):
path = tmp_path / "model_schema.json"
path = tmp_path / "model_schema"
schema = {"input": InputClass.schema(), "output": OutputClass.schema()}
path.write_text(json.dumps(schema))
monkeypatch.setenv(_MODEL_SCHEMA_PATH_ENV_VAR, str(path))


@pytest.fixture
def make_model_schema_file_no_output(tmp_path, monkeypatch):
path = tmp_path / "model_schema_no_output.json"
path = tmp_path / "model_schema_no_output"
schema = {"input": InputClass.schema()}
path.write_text(json.dumps(schema))
monkeypatch.setenv(_MODEL_SCHEMA_PATH_ENV_VAR, str(path))
15 changes: 6 additions & 9 deletions client/verta/tests/registry/test_validate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class TestValidateSchema:
)
def test_validate_schema_allow(
self,
recwarn,
make_model_schema_file,
matching_input_value,
matching_output_value,
Expand All @@ -29,8 +28,6 @@ def predict(self, input):
return matching_output_value.dict()

predict(None, matching_input_value.dict())
# verify there were no warnings
assert len(recwarn) == 0

@hypothesis.settings(
suppress_health_check=[hypothesis.HealthCheck.function_scoped_fixture],
Expand Down Expand Up @@ -67,7 +64,9 @@ def predict(self, input):
return input

# when verify_io is first, it will raise a TypeError before validate_schema is called
with pytest.raises(TypeError, match="Object of type ndarray is not JSON serializable.*"):
with pytest.raises(
TypeError, match="Object of type ndarray is not JSON serializable.*"
):
predict(None, array)

@hypothesis.settings(
Expand All @@ -76,16 +75,14 @@ def predict(self, input):
)
@hypothesis.given(matching_input_value=generate_object())
def test_validate_schema_deny_output(
self, recwarn, make_model_schema_file, matching_input_value
self, make_model_schema_file, matching_input_value
):
@validate_schema
def predict(self, input):
return input # note that this does not match the output schema

predict(None, matching_input_value.dict())
assert len(recwarn) == 1
w = recwarn.pop(UserWarning)
assert str(w.message).startswith("output failed schema validation")
with pytest.raises(ValidationError, match="output failed schema validation.*"):
predict(None, matching_input_value.dict())

@hypothesis.settings(
suppress_health_check=[hypothesis.HealthCheck.function_scoped_fixture],
Expand Down
2 changes: 1 addition & 1 deletion client/verta/verta/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
__maintainer_email__ = "miliu@verta.ai"
__title__ = "verta"
__url__ = "https://www.verta.ai/"
__version__ = "0.24.0a2"
__version__ = "0.24.0a3"
6 changes: 4 additions & 2 deletions client/verta/verta/registry/_validate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main():
def wrapper(self, input: Dict):
# fetch schema
model_schema_path = os.environ.get(
_MODEL_SCHEMA_PATH_ENV_VAR, "/app/model_schema.json"
_MODEL_SCHEMA_PATH_ENV_VAR, "/app/model_schema"
)
try:
with open(model_schema_path, "r") as file:
Expand Down Expand Up @@ -116,7 +116,9 @@ def wrapper(self, input: Dict):
try:
jsonschema.validate(instance=output, schema=output_schema)
except jsonschema.exceptions.ValidationError as e:
warnings.warn("output failed schema validation: " + str(e))
raise jsonschema.exceptions.ValidationError(
"output failed schema validation"
) from e

return output

Expand Down
4 changes: 3 additions & 1 deletion client/verta/verta/tracking/entities/_deployable_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def _get_artifact(self, key):

def log_schema(self, input: dict, output: Optional[dict] = None) -> None:
"""
Sets the input and output schemas, which are stored as model artifacts.
Sets the input and output schemas, which are stored as model artifacts. To propagate this
change to any live endpoints, you must redeploy the model by calling
:func:`~verta.endpoint.Endpoint.update`.

The output schema is optional.

Expand Down