Skip to content

Commit afd6975

Browse files
authored
Merge pull request #47 from ambiata/fix/allow-pydantic-2
[#patch] Allow Pydantic 2.x
2 parents 18f2298 + 867598d commit afd6975

File tree

8 files changed

+152
-78
lines changed

8 files changed

+152
-78
lines changed

atmosphere/custom_activity/base_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def format_prediction_payload_response(
7979
You can format the prediction the way you want based
8080
on the information returned by default
8181
"""
82-
return default_prediction_response
82+
return default_prediction_response.model_dump()
8383

8484
def get_exclusion_rule_conditions(self) -> ExclusionRuleConditionListResponse:
8585
"""

atmosphere/custom_activity/pydantic_models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Versions(BaseModelForbiddingExtraFields):
2222

2323
class PredictionResponsePayloadFormat(BaseModel):
2424
name: str
25-
description: Optional[str]
25+
description: Optional[str] = None
2626

2727

2828
class PredictionResponsePayloadFormatListResponse(BaseModel):
@@ -35,15 +35,15 @@ class Phase(BaseModel):
3535
description: str
3636
status: str
3737
start_date: datetime
38-
end_date: Optional[datetime]
38+
end_date: Optional[datetime] = None
3939

4040

4141
class Activity(BaseModel):
4242
id: UUID
4343
name: str
4444
description: str
4545
start_date: datetime
46-
end_date: Optional[datetime]
46+
end_date: Optional[datetime] = None
4747
status: str
4848
current_category: str
4949
endpoint: str
@@ -54,16 +54,16 @@ class Process(BaseModel):
5454
name: str
5555
description: str
5656
category: str
57-
start_date: Optional[datetime]
58-
end_date: Optional[datetime]
57+
start_date: Optional[datetime] = None
58+
end_date: Optional[datetime] = None
5959
status: str
6060

6161

6262
class Method(BaseModel):
6363
id: UUID
6464
name: str
6565
method_type: str
66-
config: Optional[dict]
66+
config: Optional[dict] = None
6767

6868

6969
class Action(BaseModel):
@@ -80,7 +80,7 @@ class AllocationLog(BaseModel):
8080
class InferenceInfo(BaseModel):
8181
activity: Activity
8282
current_process: Process
83-
method: Optional[Method]
83+
method: Optional[Method] = None
8484
action: Action
8585
allocation: AllocationLog
8686

poetry.lock

Lines changed: 130 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ readme = "README.md"
99

1010
[tool.poetry.dependencies]
1111
python = ">=3.9,<3.13"
12-
pydantic = ">=1.10.18,<2.0"
12+
pydantic = ">=2.0,<3.0"
1313
apscheduler = ">=3.10.1,<4.0.0"
1414
fastapi = ">=0.115.2,<1.0.0"
1515
httpx = ">=0.27.2,<1.0.0"

scripts/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest --cov=atmosphere --cov-report=term-missing "${@}"
1+
pytest -rP -vv --cov=atmosphere --cov-report=term-missing "${@}"

tests/custom_activity/activity_for_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def send_mock_prediction_request(
4141
return (
4242
requests.post(
4343
url_prediction_endpoint,
44-
json=ExpectedModel(a="a", b=3).dict(),
44+
json=ExpectedModel(a="a", b=3).model_dump(),
4545
timeout=5,
4646
),
4747
prediction_extra_info,
@@ -55,5 +55,5 @@ def send_mock_outcome_request(
5555
) -> Response:
5656
assert info_from_prediction == prediction_extra_info
5757
return requests.post(
58-
url_outcome_endpoint, json=ExpectedModel(a="b", b=2).dict(), timeout=5
58+
url_outcome_endpoint, json=ExpectedModel(a="b", b=2).model_dump(), timeout=5
5959
)

tests/custom_activity/api/test_endpoints.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _assert_204(response):
1616

1717
def test_validate_prediction(client: TestClient, example) -> None:
1818
response = client.post(
19-
"/validate-prediction-request", json=example.good_prediction.dict()
19+
"/validate-prediction-request", json=example.good_prediction.model_dump()
2020
)
2121
_assert_204(response)
2222

@@ -27,7 +27,7 @@ def test_validate_prediction_not_valid(client: TestClient, example) -> None:
2727

2828
def test_validate_outcome(client: TestClient, example) -> None:
2929
response = client.post(
30-
"/validate-outcome-request", json=example.good_prediction.dict()
30+
"/validate-outcome-request", json=example.good_prediction.model_dump()
3131
)
3232
_assert_204(response)
3333

@@ -37,7 +37,7 @@ def test_validate_outcome_not_valid(client: TestClient, example) -> None:
3737

3838

3939
def test_compute_rewards(client: TestClient, example) -> None:
40-
response = client.post("/compute-reward", json=example.good_prediction.dict())
40+
response = client.post("/compute-reward", json=example.good_prediction.model_dump())
4141
assert response.status_code == 200
4242
# Raise an exception if not if the model does not validate the payload
4343
compute_reward_response = ComputeRewardResponse.parse_obj(response.json())
@@ -63,13 +63,13 @@ def _failed_validation(client, path, example):
6363
assert response.status_code == 422
6464

6565
# Extra field
66-
data = example.good_prediction.dict()
66+
data = example.good_prediction.model_dump()
6767
data["c"] = 2
6868
response = client.post(path, json=data)
6969
assert response.status_code == 422
7070

7171
# Wrong type
72-
data = example.good_prediction.dict()
72+
data = example.good_prediction.model_dump()
7373
data["b"] = "def"
7474
response = client.post(path, json=data)
7575
assert response.status_code == 422

tests/custom_activity/test_server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def fixture_default_prediction():
1515
"id": "c22d6e7a-fd33-4f60-8e5a-0a0ab9bb1da1",
1616
"name": "kana activity",
1717
"description": "Kana mock activity",
18-
"start_date": "2020-11-06T03:17:29.600944+00:00",
18+
"start_date": "2020-11-06T03:17:29.600944Z",
1919
"end_date": None,
2020
"status": "running",
2121
"current_category": "deployment",
@@ -26,7 +26,7 @@ def fixture_default_prediction():
2626
"name": "kana",
2727
"description": "Kana mock",
2828
"category": "deployment",
29-
"start_date": "2020-11-06T03:17:29.600944+00:00",
29+
"start_date": "2020-11-06T03:17:29.600944Z",
3030
"end_date": None,
3131
"status": "running",
3232
},
@@ -84,8 +84,9 @@ def test_get_prediction_response_payload_formats(test_client: TestClient):
8484
def test_format_prediction_payload_response(
8585
test_client: TestClient, default_prediction: dict
8686
):
87-
resp = test_client.post(
88-
"/format-prediction-payload-response",
87+
resp = test_client.request(
88+
method="post",
89+
url="/format-prediction-payload-response",
8990
params={"payload_format": "test"},
9091
json=default_prediction,
9192
)

0 commit comments

Comments
 (0)