Skip to content

Conversation

@jrhoads
Copy link
Member

@jrhoads jrhoads commented Nov 18, 2025

Purpose

This PR introduces a new Django middleware to handle the deprecation of the v1 API endpoints. When enabled, this middleware will return a 410 Gone status code for any requests targeting /v1 paths, along with a message guiding users to migrate to v2.

Approach

A new Django middleware, V1DeprecationMiddleware, has been created. This middleware is added to the MIDDLEWARE setting and checks the request path. If the V1_DEPRECATED setting is enabled (controlled by an environment variable) and the request path starts with /v1/ or is exactly /v1, the middleware intercepts the request and returns a JsonResponse with a 410 Gone status. Otherwise, it allows the request to proceed to the next middleware or view.

Key Modifications

  • New Middleware: rorapi/middleware/deprecation.py containing V1DeprecationMiddleware.
  • Settings Configuration: rorapi/settings.py includes V1_DEPRECATED setting, which can be configured via the V1_DEPRECATED environment variable.
  • Middleware Integration: rorapi/settings.py adds rorapi.middleware.deprecation.V1DeprecationMiddleware to the MIDDLEWARE list.
  • New Test File: rorapi/tests/tests_unit/tests_deprecation_middleware.py with comprehensive unit tests for the new middleware.

Important Technical Details

  • The V1_DEPRECATED setting defaults to False if the environment variable is not set.
  • The middleware checks for both /v1/ (e.g., /v1/organizations) and exact /v1 paths.
  • Requests to paths other than /v1 (e.g., /v2/, /heartbeat, /) are not affected by this middleware.

Types of changes

  • New feature (non-breaking change which adds functionality)

  • Bug fix (non-breaking change which fixes an issue)

  • Breaking change (fix or feature that would cause existing functionality to change)

Reviewer, please remember our guidelines:

  • Be humble in the language and feedback you give, ask don't tell.
  • Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative.
  • Offer suggestions on how to improve code e.g. simplification or expanding clarity.
  • Ensure you give reasons for the changes you are proposing.

Copy link
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

This PR introduces a configurable Django middleware to deprecate the v1 API by returning 410 Gone responses for /v1 endpoint requests. The middleware is controlled by the V1_DEPRECATED environment variable and allows for a clean, centralized deprecation strategy.

Key Changes

  • New V1DeprecationMiddleware that intercepts v1 API requests when enabled and returns JSON:API-formatted 410 error responses
  • Environment-based configuration via V1_DEPRECATED setting with a safe default of False
  • Comprehensive test suite covering various path patterns, HTTP methods, and configuration states

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
rorapi/middleware/deprecation.py New middleware implementation that checks request paths and returns 410 responses for v1 endpoints when deprecation is enabled
rorapi/settings.py Adds V1_DEPRECATED configuration from environment variable and registers the middleware in the MIDDLEWARE list
rorapi/tests/tests_unit/tests_deprecation_middleware.py Comprehensive test suite with 11 test cases covering enabled/disabled states, different path patterns, HTTP methods, and error response format
rorapi/middleware/init.py Package initialization file for the middleware module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jrhoads jrhoads merged commit 91c7d85 into dev Nov 18, 2025
2 checks passed
@jrhoads jrhoads deleted the v1-deprecation branch December 19, 2025 11:59
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.

2 participants