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

[django] upgraded django to 4.1 #3945

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amitsrivastava
Copy link
Collaborator

Several other libraries have also been upgraded along with it. Three code changes had to be made.

  1. Django 4 wants the middlewares to be explicitly sync and async. Rather than rewriting all of the middleware classes, I took the shortcut of creating a new mixin class that supports only sync calls.

  2. CSRF_TRUSTED_ORIGINS in django 4+ need the scheme part as well. We now check and add http and https to the origins.

  3. django-babel also needs a change every time we do a django upgrade. This is mostly just changes around django version support.

There is also some change to our database support due to this. Following is the list of supported db versions.

  • PostgreSQL 11 and higher
  • MariaDB 10.3 and higher
  • MySQL 5.7 and higher
  • Oracle Database Server versions 19c and higher. Version 7.0 or higher of the cx_Oracle Python driver is required.

What changes were proposed in this pull request?

  • (Please fill in changes proposed in this fix)

How was this patch tested?

  • (Please explain how this patch was tested. Ex: unit tests, manual tests)
  • (If this patch involves UI changes, please attach a screen-shot; otherwise, remove this)

Please review Hue Contributing Guide before opening a pull request.

Copy link
Contributor

@ranade1 ranade1 left a comment

Choose a reason for hiding this comment

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

looks good.

@amitsrivastava amitsrivastava force-pushed the dev/amit/django-upgrade branch from b6ef65f to e1a6f9b Compare January 22, 2025 18:13
@amitsrivastava amitsrivastava force-pushed the dev/amit/django-upgrade branch from e1a6f9b to ac0a9dd Compare February 4, 2025 03:10
Several other libraries have also been upgraded along with it.
Four code changes had to be made.

1. Django 4 wants the middlewares to be explicitly sync and async.
Rather than rewriting all of the middleware classes, I took the
shortcut of creating a new mixin class that supports only sync calls.

2. CSRF_TRUSTED_ORIGINS in django 4+ need the scheme part as well. We
now check and add `http` and `https` to the origins.

3. django-babel also needs a change every time we do a django upgrade.
This is mostly just changes around django version support.
@amitsrivastava amitsrivastava force-pushed the dev/amit/django-upgrade branch from ac0a9dd to 1ab7b15 Compare February 5, 2025 20:54
Copy link
Collaborator

@Harshg999 Harshg999 left a comment

Choose a reason for hiding this comment

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

Added few review comments

Comment on lines +164 to +169
'''
Django4MiddlewareAdapterMixin has been solely added to migrate
Django3 middleware classes to Django4. Any new middleware
classes should try not to use this and instead follow the
standard practice at the time.
'''
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add it as a docstring?

Comment on lines +503 to +508
for origin in TRUSTED_ORIGINS:
if 'http://' in origin or 'https://' in origin:
CSRF_TRUSTED_ORIGINS.append(origin)
else:
CSRF_TRUSTED_ORIGINS.append('http://%s' % origin)
CSRF_TRUSTED_ORIGINS.append('https://%s' % origin)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused here @amitsrivastava , so if the origin is present in TRUSTED_ORIGINS, we are always appending one value in CSRF_TRUSTED_ORIGINS` else we are always appending two values for the same origin? Any reason why?

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.

3 participants