Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace parse_header with parse_header_parameters #8554

Closed
wants to merge 1 commit into from
Closed

Replace parse_header with parse_header_parameters #8554

wants to merge 1 commit into from

Conversation

jaap3
Copy link
Contributor

@jaap3 jaap3 commented Jul 12, 2022

Add a backwards compatibility shim for Django versions that have no (or an incompatible)
django.utils.http.parse_header_parameters implementation.

This is an alternative fix to the one proposed in #8543, which also attempts to fix #8540.

While making this PR I noticed that get_encoded_filename is not necesarry anymore as this is already handled correctly in Django ~1.8 (django/django@b42e5ca)

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Hey @jaap3 — thanks for this, looks good.

Just one initial comment on the compat change...

@shaib's comment from #8543 (comment) about WHY we decode() in the shim may be worth adding, for later comprehension too.

rest_framework/compat.py Outdated Show resolved Hide resolved
…tp.parse_header_parameters

Add a backwards compatibility shim for Django versions that have no (or an incompatible)
django.utils.http.parse_header_parameters implementation.
@jaap3
Copy link
Contributor Author

jaap3 commented Jul 13, 2022

I've addressed the review comments.

BTW, as this issue is only really present in django's main branch it's hard to spot the breakage in the CI, as tox is setup to allow failure for that particular "version". Looking at the results here https://github.com/encode/django-rest-framework/runs/7320233994?check_suite_focus=true#step:6:363 you'll see that djangomain now passes, when it didn't before (i.e. the most recent run for master: https://github.com/encode/django-rest-framework/runs/7094624536?check_suite_focus=true#step:6:363)

@jaap3 jaap3 requested a review from carltongibson July 13, 2022 14:20
Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

OK, looks great.

Just the one query...

# which is slightly different from the one in 4.2, it needs
# the compatibility shim as well.
from django.utils.http import parse_header_parameters
parse_header_parameters = parse_header_parameters
Copy link
Collaborator

@carltongibson carltongibson Jul 13, 2022

Choose a reason for hiding this comment

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

This line isn't needed I think. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flake8 yells at me if I don't do this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. OK. Let me have a look... 🤔

Thanks!

@carltongibson
Copy link
Collaborator

carltongibson commented Jul 13, 2022

...as tox is setup to allow failure for that particular "version".

Yes... We didn't yet get to failing on breaks against django/django main, but probably should at some point. //cc @tomchristie

@carltongibson
Copy link
Collaborator

Hi @jaap3...

flake8 yells at me if I don't do this

Hmmm 🤔 Not sure what's going on there. Passes locally for me.

Also on CI https://github.com/encode/django-rest-framework/runs/7339596012?check_suite_focus=true

I'll finish this in #8556, since the Allow maintainers to make edits box seems to be unchecked.

Thanks for the input. Great stuff! 🏅

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.

Replace parse_header (removed in Django 4.2) with parse_header_parameters
2 participants