Skip to content

Commit

Permalink
refactor(robot-server): Fix more Pydantic warnings (#17174)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring authored Dec 24, 2024
1 parent 6e43168 commit f04b221
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion robot-server/robot_server/client_data/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Key = Annotated[
str,
fastapi.Path(
regex="^[a-zA-Z0-9-_]*$",
pattern="^[a-zA-Z0-9-_]*$",
description=(
"A key for storing and retrieving the piece of data."
" This should be chosen to avoid colliding with other clients,"
Expand Down
23 changes: 17 additions & 6 deletions robot-server/tests/runs/test_run_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timezone
from pathlib import Path
from typing import List, Optional, Type
import warnings

import pytest
from decoy import Decoy
Expand Down Expand Up @@ -689,12 +690,22 @@ def test_get_state_summary_failure(
protocol_id=None,
created_at=datetime(year=2021, month=1, day=1, tzinfo=timezone.utc),
)
subject.update_run_state(
run_id="run-id",
summary=invalid_state_summary,
commands=[],
run_time_parameters=[],
)

with warnings.catch_warnings():
# Pydantic raises a warning because invalid_state_summary (deliberately)
# has a wrongly-typed value in one of its fields. Ignore the warning.
warnings.filterwarnings(
action="ignore",
category=UserWarning,
module="pydantic",
)
subject.update_run_state(
run_id="run-id",
summary=invalid_state_summary,
commands=[],
run_time_parameters=[],
)

result = subject.get_state_summary(run_id="run-id")
assert isinstance(result, BadStateSummary)
assert result.dataError.code == ErrorCodes.INVALID_STORED_DATA
Expand Down

0 comments on commit f04b221

Please sign in to comment.