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

Update django to 4.2.0, update python to 3.11 #1158

Merged
merged 25 commits into from
Jun 27, 2024

Conversation

Evert-R
Copy link
Contributor

@Evert-R Evert-R commented Jun 26, 2024

This PR updates python and django.
When CSRF_TRUSTED_ORIGINS is present, all backend tests are now succesfull, but I suggest we test this update thoroughly.
I ran all the experiments on my machine and everything seems to be working fine.

Updated:

  • Python => 3.11
  • Django => 4.2

This needs to be added to the environment variables:

See: Django documentation

Deprecated functions

  • django.utils.translation.ugettext_lazy

This is used by Django inline actions which hasn't been updated since 2021.

Fixed by: putting django.utils.translation.ugettext_lazy = gettext_lazy in base_settings.py

Behaviour changes

When creating a new playlist and selecting a csv file, the csv was always processed even though process_csv was not selected

Fixed by: Only reading the csv file to the Playlist.csv field when process_csv is selected.

Syntax changes

  • random.sample Changed in python 3.11: The population must be a sequence. Automatic conversion of sets to lists is no longer supported.

Fixed by converting the output to a list. old_songs = random.sample(list(old_new_song_set), k=n_old)

  • Flake8 config file doesn't allow inline comments anymore.

  • A lot of Admin tests were failing

Fixed by replacing:

    @classmethod
    def setUpTestData(self):
        self.factory = RequestFactory()
        self.site = AdminSite()
        self.admin = PhaseAdmin(
            Phase,
            self.site
        )

with:

    def setUp(self):
        self.admin = PhaseAdmin(model=Phase,
                                admin_site=AdminSite
                                )

In python 3.11 this caused the following error:

======================================================================
ERROR: test_search_fields (image.tests.test_admin.ImageAdminTest.test_search_fields)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/server/image/tests/test_admin.py", line 34, in test_search_fields
    self.assertEqual(self.admin.search_fields, expected_search_fields)
                     ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/test/testcases.py", line 1402, in __get__
    data = deepcopy(self.data, memo)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 146, in deepcopy
    y = copier(x, memo)
        ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
                             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/copy.py", line 161, in deepcopy
    rv = reductor(4)
         ^^^^^^^^^^^
TypeError: cannot pickle 'module' object

@Evert-R Evert-R changed the title Update er/django4.2.0 python3.11 Update django to 4.2.0, update python to 3.11 Jun 26, 2024
Copy link
Contributor

@drikusroor drikusroor left a comment

Choose a reason for hiding this comment

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

If the tests succeed and (ideally) don't take 15 minutes to complete, I'd say this is good to go. Perhaps you could deploy it to the test environment just in case before merging its to see if it works "in real life".

backend/.flake8 Show resolved Hide resolved
backend/DockerfileDevelop Show resolved Hide resolved
backend/theme/tests/test_admin.py Show resolved Hide resolved
@Evert-R
Copy link
Contributor Author

Evert-R commented Jun 26, 2024

If the tests succeed and (ideally) don't take 15 minutes to complete, I'd say this is good to go. Perhaps you could deploy it to the test environment just in case before merging its to see if it works "in real life".

Yes, I'll do that tomorrow ! Nice to have this done for my holiday

@Evert-R Evert-R merged commit ea14014 into develop Jun 27, 2024
10 checks passed
@Evert-R Evert-R deleted the update-er/django4.2.0-python3.11 branch June 27, 2024 08:33
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.

2 participants