From eac211c8b377e8d9b7ef39fa1a4b6998f1c9888a Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 9 Jun 2026 12:53:33 +0100 Subject: [PATCH 1/3] Replace cc_delim_re usage with split_header_value cc_delim_re is removed in Django 6.1b1+ --- rest_framework/compat.py | 13 +++++++++++++ rest_framework/views.py | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 5fad483911..aaffdf50f0 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -189,6 +189,19 @@ def get_referenced_base_fields_from_q(q): } +if django.VERSION >= (6, 1): + # `split_header_value` was added in Django 6.2 (backported to 6.1b1+), + # replacing the `cc_delim_re` regular expression. + # https://github.com/django/django/commit/526b1b414d8e215bf627b5722df12a09346dbf6b + from django.utils.http import split_header_value +else: + + def split_header_value(value, sep=","): + for part in value.split(sep): + if stripped := part.strip(): + yield stripped + + # `separators` argument to `json.dumps()` differs between 2.x and 3.x # See: https://bugs.python.org/issue22767 SHORT_SEPARATORS = (',', ':') diff --git a/rest_framework/views.py b/rest_framework/views.py index 327ebe9032..1439570d46 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -7,12 +7,13 @@ from django.db import connections, models from django.http import Http404 from django.http.response import HttpResponseBase -from django.utils.cache import cc_delim_re, patch_vary_headers +from django.utils.cache import patch_vary_headers from django.utils.encoding import smart_str from django.views.decorators.csrf import csrf_exempt from django.views.generic import View from rest_framework import exceptions, status +from rest_framework.compat import split_header_value from rest_framework.request import Request from rest_framework.response import Response from rest_framework.schemas import DefaultSchema @@ -444,7 +445,7 @@ def finalize_response(self, request, response, *args, **kwargs): # Add new vary headers to the response instead of overwriting. vary_headers = self.headers.pop('Vary', None) if vary_headers is not None: - patch_vary_headers(response, cc_delim_re.split(vary_headers)) + patch_vary_headers(response, split_header_value(vary_headers)) for key, value in self.headers.items(): response[key] = value From 2667400314bd6e0b5400213334189286331d3a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asif=20Saif=20Uddin=20=7B=22Auvi=22=3A=22=E0=A6=85?= =?UTF-8?q?=E0=A6=AD=E0=A6=BF=22=7D?= Date: Tue, 9 Jun 2026 20:21:57 +0600 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- rest_framework/compat.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index aaffdf50f0..18426219db 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -189,18 +189,15 @@ def get_referenced_base_fields_from_q(q): } -if django.VERSION >= (6, 1): +try: # `split_header_value` was added in Django 6.2 (backported to 6.1b1+), # replacing the `cc_delim_re` regular expression. # https://github.com/django/django/commit/526b1b414d8e215bf627b5722df12a09346dbf6b from django.utils.http import split_header_value -else: - - def split_header_value(value, sep=","): - for part in value.split(sep): - if stripped := part.strip(): - yield stripped +except ImportError: + def split_header_value(value, delimiter=","): + return [part.strip() for part in value.split(delimiter) if part.strip()] # `separators` argument to `json.dumps()` differs between 2.x and 3.x # See: https://bugs.python.org/issue22767 From 765189f8b581417dd1c1cd551067166f91a3258b Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 9 Jun 2026 22:53:29 +0100 Subject: [PATCH 3/3] Revert "Potential fix for pull request finding" This reverts commit 2667400314bd6e0b5400213334189286331d3a87. --- rest_framework/compat.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 18426219db..4a11b8d4ce 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -189,15 +189,17 @@ def get_referenced_base_fields_from_q(q): } -try: +if django.VERSION >= (6, 1): # `split_header_value` was added in Django 6.2 (backported to 6.1b1+), # replacing the `cc_delim_re` regular expression. # https://github.com/django/django/commit/526b1b414d8e215bf627b5722df12a09346dbf6b from django.utils.http import split_header_value -except ImportError: +else: - def split_header_value(value, delimiter=","): - return [part.strip() for part in value.split(delimiter) if part.strip()] + def split_header_value(value, sep=","): + for part in value.split(sep): + if stripped := part.strip(): + yield stripped # `separators` argument to `json.dumps()` differs between 2.x and 3.x # See: https://bugs.python.org/issue22767