Skip to content

MAINT Migrate internal callers of deprecated ScenarioResult.to_dict()/from_dict() to Pydantic API#2005

Open
immu4989 wants to merge 1 commit into
microsoft:mainfrom
immu4989:fix/migrate-scenario-result-deprecations
Open

MAINT Migrate internal callers of deprecated ScenarioResult.to_dict()/from_dict() to Pydantic API#2005
immu4989 wants to merge 1 commit into
microsoft:mainfrom
immu4989:fix/migrate-scenario-result-deprecations

Conversation

@immu4989

Copy link
Copy Markdown
Contributor

Fixes #2004.

ScenarioResult.to_dict() and ScenarioResult.from_dict(...) are marked for removal in 0.16.0. Internal PyRIT code still calls the deprecated forms, which emits a DeprecationWarning on every GET /api/scenarios/runs/{id}/results REST call and every CLI scenario result print.

Migration

The deprecated methods are thin wrappers around the Pydantic API. ScenarioResult.to_dict() delegates to self.model_dump(mode="json", by_alias=True) and ScenarioResult.from_dict(data) delegates to cls.model_validate(data). Output shape is identical, so the change is behavior-preserving.

Changes

  • pyrit/backend/routes/scenarios.py: REST route now returns result.model_dump(mode="json", by_alias=True) and the response annotation is tightened from dict to dict[str, Any].
  • pyrit/cli/_output.py: print_scenario_result_async deserializes with ScenarioResult.model_validate(result_dict).
  • pyrit/cli/api_client.py: docstring on the matching CLI client method describes the new payload spelling.
  • tests/unit/backend/test_scenario_run_routes.py: route test mocks model_dump instead of to_dict.
  • tests/unit/cli/test_output.py: one test mocks model_validate instead of from_dict; the roundtrip integration test uses model_dump(mode="json", by_alias=True) to produce the payload.

Verification

# Targeted tests on the changed surface:
pytest tests/unit/backend tests/unit/cli
=> 906 passed in 8.18s

# Full unit suite, no regressions:
pytest tests/unit -n auto
=> 9794 passed, 5 skipped in 42.17s

# Pre-commit (ruff format, ruff check, ty type check, etc.):
pre-commit run
=> all hooks Passed

…/from_dict() to Pydantic API

ScenarioResult.to_dict() and ScenarioResult.from_dict(...) are marked for removal in 0.16.0. Internal PyRIT code still calls the deprecated forms, emitting a DeprecationWarning on every GET /api/scenarios/runs/{id}/results REST call and every CLI scenario result print.

Both deprecated methods are thin wrappers around the Pydantic API (to_dict delegates to model_dump(mode='json', by_alias=True); from_dict delegates to model_validate). Output shape is identical, so the change is behavior-preserving.

Updates the two production call sites, three docstring references, and the matching test mocks. Also tightens the REST route return annotation from dict to dict[str, Any].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT Internal callers of ScenarioResult.to_dict()/from_dict() still emit deprecation warnings

2 participants