Skip to content

FIX address deprecation warnings#1430

Merged
romanlutz merged 14 commits intomicrosoft:mainfrom
romanlutz:romanlutz/fix-deprecation-warnings
Mar 3, 2026
Merged

FIX address deprecation warnings#1430
romanlutz merged 14 commits intomicrosoft:mainfrom
romanlutz:romanlutz/fix-deprecation-warnings

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

  • 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

Copilot AI review requested due to automatic review settings March 2, 2026 14:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_objective usage 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>
@romanlutz romanlutz force-pushed the romanlutz/fix-deprecation-warnings branch from 9b3b9de to 6217571 Compare March 2, 2026 22:42
Resolve merge conflicts in ipynb files by regenerating from .py sources.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 2, 2026 23:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

romanlutz and others added 3 commits March 2, 2026 16:44
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
romanlutz and others added 3 commits March 2, 2026 20:18
- 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
Copilot AI review requested due to automatic review settings March 3, 2026 04:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings March 3, 2026 04:54
@romanlutz romanlutz force-pushed the romanlutz/fix-deprecation-warnings branch from 0f54db6 to dc59deb Compare March 3, 2026 04:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

…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
Copilot AI review requested due to automatic review settings March 3, 2026 05:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_image returned by _add_text_to_image() is a PIL Image opened from test.png, but it is never closed before os.remove("test.png"). On Windows this can intermittently fail due to the open file handle. Close updated_image (e.g., via a context manager or try/finally) before deleting the file (or ensure _add_text_to_image closes 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>
@romanlutz romanlutz merged commit 2658a5a into microsoft:main Mar 3, 2026
38 checks passed
@romanlutz romanlutz deleted the romanlutz/fix-deprecation-warnings branch March 3, 2026 18:37
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.

3 participants