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

Fix deprecated call to HttpRequest.get_raw_uri. Closes #2296 #2302

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

rafgia
Copy link
Contributor

@rafgia rafgia commented Sep 24, 2024

According to the Django Release Notes at https://django.readthedocs.io/en/stable/releases/4.0.html:

The undocumented HttpRequest.get_raw_uri() method is removed. The HttpRequest.build_absolute_uri() method may be a suitable alternative.

This pull request replaces calls to HttpRequest.get_raw_uri with HttpRequest.build_absolute_uri() on the 404.html page. Closes #2296

Copy link
Member

@tompollard tompollard left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this @rafgia. It looks like there is a typo in the code (it should be build_absolute_uri(), not build_absolut_uri()).

@tompollard
Copy link
Member

tompollard commented Sep 24, 2024

Sorry @rafgia I should have picked this up before, but you'll see that the tests are still failing, now with the following error:

...
  File "/env3/lib/python3.9/site-packages/django/template/base.py", line 600, in compile_filter
    return FilterExpression(token, self)
  File "/env3/lib/python3.9/site-packages/django/template/base.py", line 703, in __init__
    raise TemplateSyntaxError(
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '()' from 'request.build_absolute_uri()'

The problem is that function calls inside a template do not require the parentheses (). I can't find where this is explained in the Django documentation, but you'll see the function that you are replacing doesn't include parentheses.

@tompollard
Copy link
Member

tompollard commented Sep 24, 2024

(Side note, you can run the tests locally with python manage.py test, helping to pick up problems before you open the pull request). Before running tests, you generally want to make sure that you have a fresh database by running: python manage.py resetdb followed by python manage.py loaddemo.

@tompollard
Copy link
Member

Thanks Raffaele, looks good and tests are now passing. Before we merge, please could you squash your commits? You could do this with:

# reset to the top of the dev branch
git reset bea5f64838c6d7a71d5610302c1c74e9921fb0e4

# add and commit the file again
git add physionet-django/templates/404.html
git commit -m "Fix deprecated call to HttpRequest.get_raw_uri. Closes #2296"

# Force push (forcing because you need to overwrite the commit history of your branch)
git push --force

@tompollard
Copy link
Member

Looks great, thanks Raffaele!

@tompollard tompollard merged commit cdffa90 into dev Sep 24, 2024
8 checks passed
@tompollard tompollard deleted the rg/fix404 branch September 24, 2024 20:49
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.

Link to report missing URL on 404 page fails to get the URL
2 participants