Skip to content

Commit

Permalink
pydantic >2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshburt committed Aug 21, 2024
1 parent 9d983e7 commit e1a1531
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 34 deletions.
4 changes: 0 additions & 4 deletions anaconda-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ env_specs:
- defaults:pydantic>=2.0,<3
- defaults:click
- defaults:requests
- defaults:pip
- pip:
- mlserver
- mlserver-mlflow

# Project Maintenance and Development
- defaults:anaconda-project
Expand Down
2 changes: 1 addition & 1 deletion mlflow_adsp/common/adsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_project_id() -> str:
"""

if "TOOL_PROJECT_URL" in os.environ:
# When executing within a session this seems to be the most reliable method for getting a context id.
# When executing within a session, this seems to be the most reliable method for getting a context id.
var_name: str = "TOOL_PROJECT_URL"
elif "APP_SOURCE" in os.environ:
# When executing within a scheduled job this seems to be the most reliable method for getting a context id.
Expand Down
2 changes: 1 addition & 1 deletion mlflow_adsp/common/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def execute_step(step: Step) -> ADSPSubmittedRun:
An instance of `SubmittedRun` for the requested workflow step run.
"""

step_dict: Dict = step.model_dump(by_alias=False)
step_dict: Dict = step.model_dump()
message: str = f"Launching new background job for: {step_dict}"
logger.debug(message)

Expand Down
29 changes: 3 additions & 26 deletions mlflow_adsp/contracts/dto/base_model.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
""" Base Model (Pydantic) Over-Ride """

from typing import List

# pylint: disable=no-name-in-module
from pydantic import BaseModel as PydanticBaseModel


def lower_camel_case(string: str) -> str:
"""
Alias Generator Definition
Used for externally based consumption
.
Parameters
----------
string: str
The input string to change casing of.
Returns
-------
new_string: str
A new string which has been camel cased.
"""

string_list: List[str] = string.split("_")
prefix: str = string_list[0]
suffix: str = "".join(word.capitalize() for word in string_list[1:])
return prefix + suffix


class BaseModel(PydanticBaseModel):
"""BaseModel [Pydantic] Over-Ride"""

# Pydantic Config Over-Ride
# https://pydantic-docs.helpmanual.io/usage/model_config/#options
class Config:
alias_generator = lower_camel_case
populate_by_name = True
"""Pydantic Config Over-Ride"""

arbitrary_types_allowed = True
use_enum_values = True
2 changes: 1 addition & 1 deletion test/unit/common/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_execute_step(monkeypatch):

# Review the results
mock: MagicMock = mlflow.projects.run
mock.assert_called_once_with(**Step.parse_obj({}).dict(by_alias=False))
mock.assert_called_once_with(**mock_request.model_dump())


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion test/unit/services/test_endpoint_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_poll_network_service_gracefully_fails(monkeypatch):
client: MagicMock = MagicMock()
monkeypatch.setattr(subprocess, "Popen", MockPOpen)

def mock_get(url):
def mock_get(url, timeout):
raise requests.exceptions.ConnectionError("Boom!")

monkeypatch.setattr(requests, "get", mock_get)
Expand Down

0 comments on commit e1a1531

Please sign in to comment.