Skip to content

Replace cc_delim_re usage with split_header_value for Django 6.1+ compatibility#9978

Open
laymonage wants to merge 3 commits into
encode:mainfrom
laymonage:fix/cc_delim_re
Open

Replace cc_delim_re usage with split_header_value for Django 6.1+ compatibility#9978
laymonage wants to merge 3 commits into
encode:mainfrom
laymonage:fix/cc_delim_re

Conversation

@laymonage

@laymonage laymonage commented Jun 9, 2026

Copy link
Copy Markdown

Description

cc_delim_re is removed in Django 6.2+ 6.1b1+ (ref: django/django#21438)

DRF breaks with the above change in Django, as seen in Wagtail's CI: https://github.com/wagtail/wagtail/actions/runs/27202033860/job/80308185523

Not sure if this is the best way to go about it, just thought I'd send a patch if this might help. Cheers!

Comment thread rest_framework/compat.py Outdated
Comment on lines +192 to +193
if django.VERSION >= (6, 2):
# `split_header_value` was added in Django 6.2, replacing the `cc_delim_re`

@jacobtylerwalls jacobtylerwalls Jun 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We backported this to 6.1 for inclusion in 6.1 beta, FYI

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks! Updated.

cc_delim_re is removed in Django 6.1b1+
@laymonage laymonage changed the title Replace cc_delim_re usage with split_header_value for Django 6.2+ compatibility Replace cc_delim_re usage with split_header_value for Django 6.1+ compatibility Jun 9, 2026
@auvipy auvipy requested review from auvipy and Copilot June 9, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates DRF’s handling of Vary header parsing to avoid relying on Django’s removed cc_delim_re, restoring compatibility with Django 6.1b1+ by switching to split_header_value (via a DRF compatibility shim).

Changes:

  • Replaced cc_delim_re.split(...) usage in APIView.finalize_response() with split_header_value(...).
  • Added split_header_value import/fallback shim to rest_framework.compat.

Reviewed changes

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

File Description
rest_framework/views.py Switches Vary splitting to split_header_value before calling patch_vary_headers.
rest_framework/compat.py Introduces a Django-version-dependent split_header_value shim.

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

Comment thread rest_framework/compat.py
Comment thread rest_framework/views.py
Comment on lines 445 to +448
# 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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@laymonage would you mind cross checking this suggestion?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I couldn't find any tests that exercise the existing behaviour for reference. Unfortunately I don't have time to set it up and write it myself. I can ask AI to write it if that's acceptable here…

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sure no problem

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@browniebroke browniebroke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for bringing this up, would it be worth adding 6.1a1 to the CI?

EDIT: Actually adding the version to the CI is slightly separate, and not strictly needed for this... The issue is visible when we run the tests against djangomain

@browniebroke

Copy link
Copy Markdown
Member

DRF breaks with the above change in Django, as seen in Wagtail's CI: wagtail/wagtail/actions/runs/27202033860/job/80308185523

What version of Django will you be supporting in the version of Wagtail that adds 6.1 support? We also have this PR which drops some versions:

I think that we should drop older versions before adding new ones, but would be nice to avoid being more aggressive that Wagtail

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.

5 participants