Skip to content

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

@immu4989

Description

@immu4989

What

ScenarioResult.to_dict() and ScenarioResult.from_dict(...) are marked for removal in 0.16.0, with the recommended replacements being ScenarioResult.model_dump(mode="json", by_alias=True) and ScenarioResult.model_validate(...). Internal PyRIT code still calls the deprecated forms, which emits a DeprecationWarning from pyrit/models/scenario_result.py on every GET /api/scenarios/runs/{id}/results REST call and every CLI scenario result print.

Where

Two production call sites and three docstring references:

  • pyrit/backend/routes/scenarios.py:225 calls result.to_dict() on the REST endpoint that serves scenario results.
  • pyrit/cli/_output.py:290 calls ScenarioResult.from_dict(result_dict) inside print_scenario_result_async.
  • Docstrings in pyrit/backend/routes/scenarios.py, pyrit/cli/_output.py, and pyrit/cli/api_client.py describe the REST payload as ScenarioResult.to_dict() shaped.

Why it is safe to migrate

The deprecated methods are thin wrappers that already delegate to the new Pydantic API. ScenarioResult.to_dict() returns self.model_dump(mode="json", by_alias=True) verbatim, and ScenarioResult.from_dict(data) returns cls.model_validate(data). Output dict shape is identical; only the deprecation warning goes away.

Proposed fix

Update the two call sites to use the Pydantic methods directly, refresh the three docstrings to describe the new payload spelling, and update the matching test fixtures that mock to_dict / from_dict. PR to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions