Skip to content

Replace deprecated parse_obj with model_validate in json_resource - #428

Closed
AdamMagued wants to merge 1 commit into
blindpandas:developfrom
AdamMagued:fix-pydantic-model-validate
Closed

AdamMagued wants to merge 1 commit into
blindpandas:developfrom
AdamMagued:fix-pydantic-model-validate

Conversation

@AdamMagued

Copy link
Copy Markdown

Summary

Fixes #422.

This PR replaces self.model.parse_obj(data) with self.model.model_validate(data) in bookworm/http_tools/json_resource.py.

Background and Rationale

In Pydantic v2 (pinned at >=2.4.0 in pyproject.toml), BaseModel.parse_obj() is deprecated and emits a PydanticDeprecatedSince20 warning on every call. model_validate() is the recommended method with identical semantics for validating input data against a Pydantic model.

Changes

  • Updated bookworm/http_tools/json_resource.py:RemoteJsonResource.parse_data to call self.model.model_validate(data).
  • Added unit tests in tests/test_json_resource.py covering:
    • Successful payload validation into model instance.
    • Ensuring no PydanticDeprecatedSince20 deprecation warning is emitted.
    • Handling of validation errors raising ValueError.
    • HTTP retrieval and error scenarios (ConnectionError, invalid JSON).

Verification

  • Ran unit tests: pytest tests/ -k json_resource (all 7 tests passed).
  • Verified code passes linting and formatting via Ruff.

In bookworm/http_tools/json_resource.py, replace BaseModel.parse_obj with model_validate to conform with Pydantic v2 and prevent PydanticDeprecatedSince20 warnings. Add unit tests for RemoteJsonResource covering successful validation, deprecation warning suppression, error handling, and request retrieval. Fixes blindpandas#422.
@AdamMagued

Copy link
Copy Markdown
Author

Closing in favor of earlier community PR #423 to avoid duplicate review effort.

@AdamMagued AdamMagued closed this Oct 2, 2026
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.

Replace deprecated parse_obj with model_validate in json_resource.py

1 participant