FIX address deprecation warnings#1430
Merged
romanlutz merged 14 commits intomicrosoft:mainfrom Mar 3, 2026
Merged
Conversation
Contributor
romanlutz
commented
Mar 2, 2026
- Replace HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT (starlette)
- Replace Pillow getdata() with get_flattened_data() in tests
- Fix pypdf replace_contents() deprecation using PdfWriter(clone_from=reader)
- Update is_objective=True to seed_type='objective' in doc notebooks
- Remove stale deprecation warning outputs from notebook .ipynb files
Contributor
There was a problem hiding this comment.
Pull request overview
Addresses multiple deprecation warnings across the backend API, PDF conversion utilities, tests, and documentation artifacts to keep the codebase compatible with newer dependency versions.
Changes:
- Update FastAPI/Starlette validation error handling to use the non-deprecated 422 status constant.
- Update unit tests to avoid deprecated Pillow pixel extraction APIs.
- Update PDF modification flow to avoid deprecated pypdf page content replacement, and refresh docs/notebooks to remove deprecated
is_objectiveusage and stale warning outputs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/converter/test_add_text_image_converter.py | Switch pixel extraction in tests to the newer Pillow API to avoid deprecation warnings. |
| tests/unit/converter/test_add_image_text_converter.py | Same Pillow deprecation fix for image/text converter tests. |
| pyrit/prompt_converter/pdf_converter.py | Use PdfWriter(clone_from=reader) and operate on attached pages to avoid pypdf deprecations. |
| pyrit/backend/middleware/error_handlers.py | Replace deprecated Starlette 422 constant usage in validation error responses. |
| doc/code/targets/2_openai_responses_target.ipynb | Remove captured stderr deprecation warning outputs from committed notebook. |
| doc/code/memory/8_seed_database.py | Update docs example to use seed_type="objective" instead of deprecated is_objective=True. |
| doc/code/memory/8_seed_database.ipynb | Same seed_type update in notebook version of the docs. |
| doc/code/datasets/1_loading_datasets.py | Update docs example to use seed_type="objective" instead of deprecated is_objective=True. |
| doc/code/datasets/1_loading_datasets.ipynb | Apply the same docs update and remove captured deprecation warning output. |
- Replace HTTP_422_UNPROCESSABLE_ENTITY with HTTP_422_UNPROCESSABLE_CONTENT (starlette) - Replace Pillow getdata() with get_flattened_data() in tests - Fix pypdf replace_contents() deprecation using PdfWriter(clone_from=reader) - Update is_objective=True to seed_type='objective' in doc notebooks - Remove stale deprecation warning outputs from notebook .ipynb files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9b3b9de to
6217571
Compare
Resolve merge conflicts in ipynb files by regenerating from .py sources. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…om/romanlutz/PyRIT into romanlutz/fix-deprecation-warnings # Conflicts: # doc/code/datasets/1_loading_datasets.ipynb # doc/code/targets/2_openai_responses_target.ipynb # pyrit/backend/routes/attacks.py # tests/unit/setup/test_airt_targets_initializer.py
rlundeen2
approved these changes
Mar 3, 2026
- Close PIL Image file handles before os.remove (Windows compat) - Remove 'Unclosed client session' stderr from responses notebook - Add E402, E501 to doc/ per-file-ignores - Fix E712, E722, E731 violations from merged main - Fix mypy cross-platform issue in attack_manager.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…om/romanlutz/PyRIT into romanlutz/fix-deprecation-warnings # Conflicts: # pyproject.toml
…tion-warnings # Conflicts: # pyproject.toml
…tion-warnings # Conflicts: # pyproject.toml
0f54db6 to
dc59deb
Compare
…tion-warnings # Conflicts: # doc/code/datasets/1_loading_datasets.ipynb
…om/romanlutz/PyRIT into romanlutz/fix-deprecation-warnings # Conflicts: # doc/code/datasets/1_loading_datasets.ipynb
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
tests/unit/converter/test_add_image_text_converter.py:79
updated_imagereturned by_add_text_to_image()is a PILImageopened fromtest.png, but it is never closed beforeos.remove("test.png"). On Windows this can intermittently fail due to the open file handle. Closeupdated_image(e.g., via a context manager ortry/finally) before deleting the file (or ensure_add_text_to_imagecloses the underlying image file).
with Image.open("test.png") as image:
pixels_before = list(image.get_flattened_data())
updated_image = converter._add_text_to_image("Sample Text!")
pixels_after = list(updated_image.get_flattened_data())
assert updated_image
# Check if at least one pixel changed, indicating that text was added
assert pixels_before != pixels_after
os.remove("test.png")
Move output_pdf.getvalue() return inside the try block so that output_pdf is never referenced in an unbound state, and linters don't flag a potentially unbound variable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.