Skip to content

Commit 7a6effe

Browse files
authored
Merge pull request #1499 from python-discord/dependabot/pip/djangorestframework-3.16.0
Bump djangorestframework from 3.14.0 to 3.16.0
2 parents e944f0a + 1b81162 commit 7a6effe

File tree

11 files changed

+61
-105
lines changed

11 files changed

+61
-105
lines changed

poetry.lock

Lines changed: 20 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydis_site/apps/api/tests/test_bumped_threads.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ def test_returns_404_for_non_existing_data(self):
6060

6161
response = self.client.get(url)
6262
self.assertEqual(response.status_code, 404)
63-
self.assertEqual(response.json(), {"detail": "Not found."})
63+
self.assertEqual(
64+
response.json(),
65+
{"detail": "No BumpedThread matches the given query."},
66+
)

pydis_site/apps/api/tests/test_filters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,15 @@ def test_fetch_non_existing(self) -> None:
210210
sequence.model.objects.all().delete()
211211

212212
response = self.client.get(f"{sequence.url()}/42")
213+
if "filter-lists" in sequence.url():
214+
kind = "FilterList"
215+
else:
216+
kind = "Filter"
213217
self.assertEqual(response.status_code, 404)
214-
self.assertDictEqual(response.json(), {'detail': 'Not found.'})
218+
self.assertDictEqual(
219+
response.json(),
220+
{'detail': f"No {kind} matches the given query."},
221+
)
215222

216223
def test_creation(self) -> None:
217224
for name, sequence in get_test_sequences().items():

pydis_site/apps/api/tests/test_infractions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_partial_update(self):
329329

330330
def test_partial_update_returns_400_for_frozen_field(self):
331331
url = reverse('api:bot:infraction-detail', args=(self.ban_hidden.id,))
332-
data = {'user': 6}
332+
data = {'user': 6, 'active': True}
333333

334334
response = self.client.patch(url, data=data)
335335
self.assertEqual(response.status_code, 400)
@@ -559,7 +559,7 @@ def test_returns_400_for_second_active_infraction_of_the_same_type(self):
559559
second_response.json(),
560560
{
561561
'non_field_errors': [
562-
'This user already has an active infraction of this type.'
562+
'The fields user, type must make a unique set.'
563563
]
564564
}
565565
)
@@ -824,7 +824,7 @@ def test_is_valid_if_active_infraction_with_same_fields_exists(self):
824824
self.create_infraction('ban', active=True)
825825
instance = self.create_infraction('ban', active=False)
826826

827-
data = {'reason': 'hello'}
827+
data = {'reason': 'hello', 'active': True}
828828
serializer = InfractionSerializer(instance, data=data, partial=True)
829829

830830
self.assertTrue(serializer.is_valid(), msg=serializer.errors)

pydis_site/apps/api/tests/test_nominations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def test_returns_404_on_get_unknown_nomination(self):
379379
response = self.client.get(url, data={})
380380
self.assertEqual(response.status_code, 404)
381381
self.assertEqual(response.json(), {
382-
"detail": "Not found."
382+
"detail": "No Nomination matches the given query."
383383
})
384384

385385
def test_returns_404_on_patch_unknown_nomination(self):
@@ -391,7 +391,7 @@ def test_returns_404_on_patch_unknown_nomination(self):
391391
response = self.client.patch(url, data={})
392392
self.assertEqual(response.status_code, 404)
393393
self.assertEqual(response.json(), {
394-
"detail": "Not found."
394+
"detail": "No Nomination matches the given query."
395395
})
396396

397397
def test_returns_405_on_list_put(self):

pydis_site/apps/api/tests/test_roles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,7 @@ def test_role_detail_404_all_methods(self):
208208
for method in ('get', 'put', 'patch', 'delete'):
209209
response = getattr(self.client, method)(url)
210210
self.assertEqual(response.status_code, 404)
211-
self.assertJSONEqual(response.content, '{"detail": "Not found."}')
211+
self.assertJSONEqual(
212+
response.content,
213+
'{"detail": "No Role matches the given query."}',
214+
)

pydis_site/apps/api/tests/test_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def verify_adding_existing_alt(self, add_on_source: bool) -> None:
746746
response = self.client.post(repeated_url, repeated_data)
747747
self.assertEqual(response.status_code, 400)
748748
self.assertEqual(response.json(), {
749-
'source': ["This relationship has already been established"]
749+
'non_field_errors': ["The fields source, target must make a unique set."]
750750
})
751751

752752
def test_removing_existing_alt_source_from_target(self) -> None:

pydis_site/apps/api/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828

2929
# https://www.django-rest-framework.org/api-guide/routers/#defaultrouter
3030
bot_router = DefaultRouter(trailing_slash=False)
31+
# XXX: We should probably figure out why we have this registered twice.
3132
bot_router.register(
3233
'filter/filter_lists',
33-
FilterListViewSet
34+
FilterListViewSet,
35+
basename="filter-filterlists-list",
3436
)
3537
bot_router.register(
3638
"aoc-account-links",
@@ -62,7 +64,7 @@
6264
)
6365
bot_router.register(
6466
'filter-lists',
65-
FilterListViewSet
67+
FilterListViewSet,
6668
)
6769
bot_router.register(
6870
'infractions',

pydis_site/apps/api/viewsets/bot/infraction.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ def create(self, request: HttpRequest, *args, **kwargs) -> Response:
284284
"""
285285
try:
286286
return super().create(request, *args, **kwargs)
287-
except IntegrityError as err:
287+
except IntegrityError as err: # pragma: no cover - see below
288+
# Not covered: DRF handles this via `UniqueTogetherValidator` these
289+
# days, which means it's hard to test this branch specifically.
290+
# However, in a productive deployment, it's still very much
291+
# possible for two concurrent inserts to run into IntegrityError.
292+
288293
# We need to use `__cause__` here, as Django reraises the internal
289294
# UniqueViolation emitted by psycopg2 (which contains the attribute
290295
# that we actually need)

pydis_site/apps/api/viewsets/bot/user.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,14 @@ def add_alt(self, request: Request, pk: str) -> Response:
395395
raise ParseError(detail={
396396
"source": ["The user may not be an alternate account of itself"]
397397
})
398-
if err.__cause__.diag.constraint_name == 'api_useraltrelationship_unique_relationships':
398+
if (
399+
err.__cause__.diag.constraint_name == 'api_useraltrelationship_unique_relationships'
400+
): # pragma: no cover - see below
401+
# This is not covered because newer DRF versions automatically validate this,
402+
# however the validation is done via a SELECT query which may race concurrent
403+
# inserts in prod. The only correct way is e.g. what Ecto does which is
404+
# associating the validators to the unique constraint errors to match in
405+
# errors, anything else may race.
399406
raise ParseError(detail={
400407
"source": ["This relationship has already been established"]
401408
})

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ django-environ = "0.11.2"
1515
django-filter = "25.1"
1616
django-prometheus = "2.3.1"
1717
django-simple-bulma = "2.6.0"
18-
djangorestframework = "3.14.0"
18+
djangorestframework = "3.16.0"
1919
gunicorn = "23.0.0"
2020
httpx = "0.28.1"
2121
markdown = "3.7"

0 commit comments

Comments
 (0)