Skip to content

Upgrade Django to 5.2 #12149

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

Merged
merged 8 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ filterwarnings =
ignore:DateTimeField .* received a naive datetime .* while time zone support is active:RuntimeWarning
ignore:.*:DeprecationWarning

# TODO: uncomment after upgrading to Django 5.2.x
# ignore:.*:django.utils.deprecation.RemovedInDjango60Warning
ignore:.*:django.utils.deprecation.RemovedInDjango60Warning
ignore:.*:elasticsearch.exceptions.ElasticsearchWarning
ignore:.*:PendingDeprecationWarning
50 changes: 14 additions & 36 deletions readthedocs/gold/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests_mock
from unittest import mock

import django_dynamic_fixture as fixture
Expand All @@ -11,44 +12,21 @@ class GoldSignalTests(TestCase):
def setUp(self):
self.user = fixture.get(User)

# Mocking
self.patches = {}
self.mocks = {}
self.patches["requestor"] = mock.patch("stripe.api_requestor.APIRequestor")

for patch in self.patches:
self.mocks[patch] = self.patches[patch].start()

self.mocks["request"] = self.mocks["requestor"].return_value

def tearDown(self):
# TODO: refactor to use request_mocks for these. The current mock
# pattern breaks tests ran after these if tearDown is not called with
# the `.stop` for all the patches. It took me a lot of time to realized
# about this problem.
for _, patch in self.patches.items():
patch.stop()

def mock_request(self, resp=None):
if resp is None:
resp = ({}, "")
self.mocks["request"].request = mock.Mock(side_effect=resp)

def test_delete_subscription(self):
@requests_mock.Mocker(kw="mock_request")
def test_delete_subscription(self, mock_request):
subscription = fixture.get(GoldUser, user=self.user, stripe_id="cus_123")
self.assertIsNotNone(subscription)
self.mock_request(
[
({"id": "cus_123", "object": "customer"}, ""),
({"deleted": True, "customer": "cus_123"}, ""),
]
mock_request.get(
"https://api.stripe.com/v1/customers/cus_123",
json={"id": "cus_123", "object": "customer"},
)
mock_request.delete(
"https://api.stripe.com/v1/customers/cus_123",
json={"deleted": True, "customer": "cus_123"},
)

subscription.delete()

self.mocks["request"].request.assert_has_calls(
[
mock.call("get", "/v1/customers/cus_123", {}, mock.ANY),
mock.call("delete", "/v1/customers/cus_123", {}, mock.ANY),
]
)
assert mock_request.request_history[0]._request.method == "GET"
assert mock_request.request_history[0]._request.url == "https://api.stripe.com/v1/customers/cus_123"
assert mock_request.request_history[1]._request.method == "DELETE"
assert mock_request.request_history[1]._request.url == "https://api.stripe.com/v1/customers/cus_123"
2 changes: 1 addition & 1 deletion readthedocs/oauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class GitHubAppInstallation(TimeStampedModel):
)
target_type = models.CharField(
help_text=_("Account type that the target_id belongs to (user or organization)"),
choices=GitHubAccountType.choices,
choices=GitHubAccountType,
max_length=255,
)
extra_data = models.JSONField(
Expand Down
13 changes: 0 additions & 13 deletions readthedocs/subscriptions/tests/test_event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,3 @@ def test_subscription_precedence(self):

self.organization.refresh_from_db()
assert self.organization.stripe_subscription == stripe_subscription

def test_register_events(self):
def test_func():
pass

with override_settings(RTD_ALLOW_ORGANIZATIONS=False):
event_handlers.handler("event")(test_func)

self.assertEqual(webhooks.registrations["event"], [])

with override_settings(RTD_ALLOW_ORGANIZATIONS=True):
event_handlers.handler("event")(test_func)
self.assertEqual(webhooks.registrations["event"], [test_func])
11 changes: 5 additions & 6 deletions requirements/deploy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ distlib==0.3.9
# virtualenv
dj-pagination==2.5.0
# via -r requirements/pip.txt
dj-stripe==2.6.3
dj-stripe==2.9.0
# via -r requirements/pip.txt
django==4.2.20
django==5.2
# via
# -r requirements/pip.txt
# dj-stripe
Expand Down Expand Up @@ -244,9 +244,7 @@ jmespath==1.0.1
# boto3
# botocore
jsonfield==3.1.0
# via
# -r requirements/pip.txt
# dj-stripe
# via -r requirements/pip.txt
kombu==5.5.3
# via
# -r requirements/pip.txt
Expand Down Expand Up @@ -405,7 +403,7 @@ sqlparse==0.5.3
# django-debug-toolbar
stack-data==0.6.3
# via ipython
stripe==4.2.0
stripe==11.6.0
# via
# -r requirements/pip.txt
# dj-stripe
Expand Down Expand Up @@ -434,6 +432,7 @@ typing-extensions==4.13.2
# pydantic
# pydantic-core
# pygithub
# stripe
# typing-inspection
typing-inspection==0.4.0
# via
Expand Down
11 changes: 5 additions & 6 deletions requirements/docker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ distlib==0.3.9
# virtualenv
dj-pagination==2.5.0
# via -r requirements/pip.txt
dj-stripe==2.6.3
dj-stripe==2.9.0
# via -r requirements/pip.txt
django==4.2.20
django==5.2
# via
# -r requirements/pip.txt
# dj-stripe
Expand Down Expand Up @@ -257,9 +257,7 @@ jmespath==1.0.1
# boto3
# botocore
jsonfield==3.1.0
# via
# -r requirements/pip.txt
# dj-stripe
# via -r requirements/pip.txt
kombu==5.5.3
# via
# -r requirements/pip.txt
Expand Down Expand Up @@ -433,7 +431,7 @@ sqlparse==0.5.3
# django-debug-toolbar
stack-data==0.6.3
# via ipython
stripe==4.2.0
stripe==11.6.0
# via
# -r requirements/pip.txt
# dj-stripe
Expand Down Expand Up @@ -461,6 +459,7 @@ typing-extensions==4.13.2
# pydantic
# pydantic-core
# pygithub
# stripe
# typing-inspection
typing-inspection==0.4.0
# via
Expand Down
19 changes: 7 additions & 12 deletions requirements/pip.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pip
virtualenv

django~=4.2.0
django~=5.2.0
django-extensions
django-polymorphic
django-autoslug
Expand Down Expand Up @@ -79,19 +79,14 @@ orjson
django-gravatar2
pytz

# We cannot upgrade it until dj-stripe fixes this issue
# https://github.com/dj-stripe/dj-stripe/issues/1842
stripe==4.2.0

regex

# NOTE: djstripe overrides the stripe api version
# globally, when updating make sure our code is compatible
# with the version used by djstripe.
# See STRIPE_API_VERSION https://dj-stripe.dev/reference/settings/.
# dj-stripe==2.7.0 requires some extra actions to be upgrade
# See https://github.com/readthedocs/readthedocs.org/issues/9706
dj-stripe==2.6.3
# Stripe is pinned because 12.0.1 fails with
#
# AttributeError: module 'stripe' has no attribute 'UsageRecord'
stripe<12

dj-stripe==2.9.0

markdown

Expand Down
11 changes: 5 additions & 6 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ distlib==0.3.9
# via virtualenv
dj-pagination==2.5.0
# via -r requirements/pip.in
dj-stripe==2.6.3
dj-stripe==2.9.0
# via -r requirements/pip.in
django==4.2.20
django==5.2
# via
# -r requirements/pip.in
# dj-stripe
Expand Down Expand Up @@ -187,9 +187,7 @@ jmespath==1.0.1
# boto3
# botocore
jsonfield==3.1.0
# via
# -r requirements/pip.in
# dj-stripe
# via -r requirements/pip.in
kombu==5.5.3
# via celery
lexid==2021.1006
Expand Down Expand Up @@ -296,7 +294,7 @@ sqlparse==0.5.3
# via
# django
# django-debug-toolbar
stripe==4.2.0
stripe==11.6.0
# via
# -r requirements/pip.in
# dj-stripe
Expand All @@ -315,6 +313,7 @@ typing-extensions==4.13.2
# pydantic
# pydantic-core
# pygithub
# stripe
# typing-inspection
typing-inspection==0.4.0
# via pydantic
Expand Down
11 changes: 5 additions & 6 deletions requirements/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ distlib==0.3.9
# virtualenv
dj-pagination==2.5.0
# via -r requirements/pip.txt
dj-stripe==2.6.3
dj-stripe==2.9.0
# via -r requirements/pip.txt
django==4.2.20
django==5.2
# via
# -r requirements/pip.txt
# dj-stripe
Expand Down Expand Up @@ -253,9 +253,7 @@ jmespath==1.0.1
# boto3
# botocore
jsonfield==3.1.0
# via
# -r requirements/pip.txt
# dj-stripe
# via -r requirements/pip.txt
kombu==5.5.3
# via
# -r requirements/pip.txt
Expand Down Expand Up @@ -445,7 +443,7 @@ sqlparse==0.5.3
# -r requirements/pip.txt
# django
# django-debug-toolbar
stripe==4.2.0
stripe==11.6.0
# via
# -r requirements/pip.txt
# dj-stripe
Expand All @@ -468,6 +466,7 @@ typing-extensions==4.13.2
# pydantic-core
# pygithub
# sphinx
# stripe
# typing-inspection
typing-inspection==0.4.0
# via
Expand Down