Skip to content

Remove deprecated extension legacy hooks#4226

Open
Ckk3 wants to merge 3 commits intostrawberry-graphql:mainfrom
Ckk3:deprecation/extension-hooks
Open

Remove deprecated extension legacy hooks#4226
Ckk3 wants to merge 3 commits intostrawberry-graphql:mainfrom
Ckk3:deprecation/extension-hooks

Conversation

@Ckk3
Copy link
Collaborator

@Ckk3 Ckk3 commented Feb 10, 2026

Description

Remove deprecated extension legacy hooks (on_request_start, on_request_end, on_validation_start, on_validation_end, on_parsing_start, on_parsing_end), deprecated since 0.159.0.

Migration guide

Before (deprecated):

class MyExtension(SchemaExtension):
    def on_request_start(self):
        ...

    def on_request_end(self):
        ...

After:

class MyExtension(SchemaExtension):
    def on_operation(self):
        # on_request_start logic
        yield
        # on_request_end logic

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Remove support for legacy extension lifecycle hooks in favour of the new event-driven hooks.

Enhancements:

  • Simplify extension context managers to only handle the new hook API and drop legacy compatibility paths, including mixed legacy/new validation.

Documentation:

  • Add release notes and migration guide for removing deprecated extension legacy hooks.

Tests:

  • Remove tests for legacy hook behaviour and update references to the new hook names in existing tests.

@Ckk3 Ckk3 self-assigned this Feb 10, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 10, 2026

Reviewer's Guide

Removes support for deprecated legacy extension hooks in the extension context management system, cleans up associated compatibility logic and tests, and documents the change and migration path in RELEASE notes.

File-Level Changes

Change Details Files
Drop support for legacy extension lifecycle hooks in the extension context manager implementation.
  • Remove legacy hook name attributes and deprecation messaging from the base extension context manager.
  • Remove logic that detected legacy start/end hooks, emitted deprecation warnings, and wrapped them into the new event-driven hook API.
  • Simplify concrete context manager implementations to only reference the new hook methods (on_operation, on_validate, on_parse, on_execute).
  • Adjust type-checking imports now that legacy wrapping helpers are gone.
strawberry/extensions/context.py
Remove tests and comments related to legacy extension hooks and their deprecation behavior.
  • Delete tests that verified mixed legacy/new usage errors and compatibility behavior for legacy start/end hooks.
  • Update test comments to reference the on_execute hook instead of the old on_executing_start hook.
  • Keep remaining extension tests intact to validate the current hook API.
tests/schema/extensions/schema_extensions/test_extensions.py
Document removal of legacy extension hooks and provide migration guidance.
  • Add a new RELEASE entry marking this as a minor release.
  • Describe which legacy hooks were removed and show how to migrate to the on_operation hook pattern using a contextmanager-style implementation.
RELEASE.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2026

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Ckk3:deprecation/extension-hooks (c745f08) with main (f28e74c)

Open in CodSpeed

@Ckk3 Ckk3 marked this pull request as ready for review February 15, 2026 18:04
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `RELEASE.md:3` </location>
<code_context>
+Release type: minor
+
+Remove deprecated extension legacy hooks (`on_request_start`, `on_request_end`, `on_validation_start`, `on_validation_end`, `on_parsing_start`, `on_parsing_end`), deprecated since [0.159.0](https://github.com/strawberry-graphql/strawberry/releases/tag/0.159.0).
+
+### Migration guide
</code_context>

<issue_to_address>
**suggestion (typo):** Consider reordering the phrase "deprecated extension legacy hooks" for clarity.

You could rephrase this as “deprecated legacy extension hooks” or just “legacy extension hooks” to read more naturally.

```suggestion
Remove deprecated legacy extension hooks (`on_request_start`, `on_request_end`, `on_validation_start`, `on_validation_end`, `on_parsing_start`, `on_parsing_end`), deprecated since [0.159.0](https://github.com/strawberry-graphql/strawberry/releases/tag/0.159.0).
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@botberry
Copy link
Member

botberry commented Feb 15, 2026

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Remove deprecated legacy extension hooks (on_request_start, on_request_end, on_validation_start, on_validation_end, on_parsing_start, on_parsing_end), deprecated since 0.159.0.

Migration guide

Before (deprecated):

class MyExtension(SchemaExtension):
    def on_request_start(self): ...

    def on_request_end(self): ...

After:

class MyExtension(SchemaExtension):
    def on_operation(self):
        # on_request_start logic
        yield
        # on_request_end logic

Here's the tweet text:

🆕 Release (next) is out! Thanks to Luis Gustavo for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 15, 2026

Greptile Summary

This PR completes the deprecation cycle for legacy extension hooks (on_request_start, on_request_end, on_validation_start, on_validation_end, on_parsing_start, on_parsing_end) that were deprecated in version 0.159.0.

Key Changes:

  • Removed all legacy hook compatibility code from ExtensionContextManagerBase
  • Eliminated the from_legacy() method that converted old-style hooks to context managers
  • Removed __init_subclass__ and related deprecation warning infrastructure
  • Cleaned up __slots__ by removing deprecation_message attribute
  • Removed LEGACY_ENTER, LEGACY_EXIT, and DEPRECATION_MESSAGE class attributes from all context managers
  • Deleted 184 lines of legacy hook tests including tests for deprecation warnings, mixed hook usage, and partial hook implementations
  • Added clear migration documentation in RELEASE.md showing the transition to on_operation style hooks

The migration path is straightforward: logic that was split between on_*_start and on_*_end methods now goes before and after a yield statement in the corresponding new-style hook (on_operation, on_validate, on_parse, on_execute).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward removal of deprecated code that has been deprecated for multiple versions. All legacy hook support code, deprecation warnings, and related tests have been cleanly removed. The changes are well-contained and properly documented with a clear migration guide. No remaining references to the deprecated hooks exist in the core codebase (only in historical CHANGELOG and documentation files).
  • No files require special attention

Important Files Changed

Filename Overview
RELEASE.md Documents removal of legacy hooks with clear migration guide for users upgrading
strawberry/extensions/context.py Cleanly removes all legacy hook compatibility code, deprecation warnings, and related methods
tests/schema/extensions/schema_extensions/test_extensions.py Removes 184 lines of legacy hook tests while preserving all new-style hook tests and functionality

Flowchart

flowchart TD
    A[Extension Lifecycle] --> B{Hook Type}
    
    B -->|Operation| C[on_operation]
    B -->|Validation| D[on_validate]
    B -->|Parsing| E[on_parse]
    B -->|Execution| F[on_execute]
    
    C --> C1[Before operation logic]
    C1 --> C2[yield]
    C2 --> C3[After operation logic]
    
    D --> D1[Before validation logic]
    D1 --> D2[yield]
    D2 --> D3[After validation logic]
    
    E --> E1[Before parsing logic]
    E1 --> E2[yield]
    E2 --> E3[After parsing logic]
    
    F --> F1[Before execution logic]
    F1 --> F2[yield]
    F2 --> F3[After execution logic]
    
    style C fill:#90EE90
    style D fill:#90EE90
    style E fill:#90EE90
    style F fill:#90EE90
Loading

Last reviewed commit: 2e28524

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants