-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: chore(deps): Upgrade to Django 5.2 #177
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
base: main
Are you sure you want to change the base?
Changes from all commits
d6e2d2f
c37cefd
62260c9
85de68d
5899cd8
f3bb0e7
e0b02f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| import logging | ||
|
|
||
| from asgiref.sync import sync_to_async | ||
| from channels.db import database_sync_to_async | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if my understanding is correct this is basically like some additional ORM aware niceties that channels takes advantage of. this seems like a very good change. |
||
| from channels.generic.websocket import AsyncJsonWebsocketConsumer | ||
|
|
||
| from scram.route_manager.models import Entry, WebSocketSequenceElement | ||
|
|
@@ -23,19 +23,21 @@ async def connect(self): | |
| await self.accept() | ||
|
|
||
| # Filter WebSocketSequenceElements by actiontype | ||
| elements = await sync_to_async(list)( | ||
| elements = await database_sync_to_async(list)( | ||
| WebSocketSequenceElement.objects.filter(action_type__name=self.actiontype).order_by("order_num"), | ||
| ) | ||
| if not elements: | ||
| logger.warning("No elements found for actiontype=%s.", self.actiontype) | ||
| return | ||
|
|
||
| # Avoid lazy evaluation | ||
| routes = await sync_to_async(list)(Entry.objects.filter(is_active=True).values_list("route__route", flat=True)) | ||
| routes = await database_sync_to_async(list)( | ||
| Entry.objects.filter(is_active=True).values_list("route__route", flat=True) | ||
| ) | ||
|
|
||
| for route in routes: | ||
| for element in elements: | ||
| msg = await sync_to_async(lambda e: e.websocketmessage)(element) | ||
| msg = await database_sync_to_async(lambda e: e.websocketmessage)(element) | ||
| msg.msg_data[msg.msg_data_route_field] = str(route) | ||
| await self.send_json({"type": msg.msg_type, "message": msg.msg_data}) | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get the idea and I'm not opposed to dropping versioning, but on the other hand it seems like it's generally been better for us than just taking anything. Maybe we can find a middle ground and just do major version pinning? This goes for all the requirements files. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,32 @@ | ||
| argon2-cffi==21.3.0 # https://github.com/hynek/argon2_cffi | ||
| argon2-cffi # https://github.com/hynek/argon2_cffi | ||
| autobahn<25.10.1 # Pin to avoid v25.10.1 that is giving build troubles. | ||
| django-celery-beat # https://github.com/celery/django-celery-beat | ||
| django-netfields # https://pypi.org/project/django-netfields/ | ||
| flower==1.0.0 # https://github.com/mher/flower | ||
| python-slugify==6.1.2 # https://github.com/un33k/python-slugify | ||
| uvicorn[standard]==0.17.6 # https://github.com/encode/uvicorn | ||
| whitenoise==6.2.0 # https://github.com/evansd/whitenoise | ||
| flower # https://github.com/mher/flower | ||
| python-slugify # https://github.com/un33k/python-slugify | ||
| uvicorn[standard] # https://github.com/encode/uvicorn | ||
| whitenoise # https://github.com/evansd/whitenoise | ||
|
|
||
| # Django | ||
| # ------------------------------------------------------------------------------ | ||
| channels_redis==3.4.0 | ||
| crispy-bootstrap5==0.6 # https://github.com/django-crispy-forms/crispy-bootstrap5 | ||
| django~=4.2 # https://www.djangoproject.com/ | ||
| channels_redis | ||
| crispy-bootstrap5 # https://github.com/django-crispy-forms/crispy-bootstrap5 | ||
| django~=5.2 # https://www.djangoproject.com/ | ||
| django-crispy-forms | ||
|
|
||
| django-allauth==0.51.0 # https://github.com/pennersr/django-allauth | ||
| django-environ==0.9.0 # https://github.com/joke2k/django-environ | ||
| django-eventstream==4.5.1 # https://github.com/fanout/django-eventstream | ||
| django-model-utils==4.2.0 # https://github.com/jazzband/django-model-utils | ||
| django-redis==5.3.0 | ||
| django-simple-history~=3.1.1 | ||
| django-allauth # https://github.com/pennersr/django-allauth | ||
| django-environ # https://github.com/joke2k/django-environ | ||
| django-eventstream # https://github.com/fanout/django-eventstream | ||
| django-model-utils # https://github.com/jazzband/django-model-utils | ||
| django-redis | ||
| django-simple-history | ||
|
|
||
| # Django REST Framework | ||
| djangorestframework~=3.15 # https://github.com/encode/django-rest-framework | ||
| django-cors-headers==3.13.0 # https://github.com/adamchainz/django-cors-headers | ||
| djangorestframework # https://github.com/encode/django-rest-framework | ||
| django-cors-headers # https://github.com/adamchainz/django-cors-headers | ||
| drf-spectacular # https://github.com/tfranzel/drf-spectacular | ||
|
|
||
| # OIDC | ||
| # ------------------------------------------------------------------------------ | ||
| mozilla_django_oidc==4.0.1 # https://github.com/mozilla/mozilla-django-oidc | ||
| mozilla-django-oidc # https://github.com/mozilla/mozilla-django-oidc | ||
|
|
||
| websockets~=10.3 | ||
| websockets |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice this would close (or at least go a long way towards closing) #168 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Generated manually to replace deprecated index_together with indexes | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("route_manager", "0034_alter_entry_originating_scram_instance_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| # HistoricalActionType | ||
| migrations.AlterModelOptions( | ||
| name="historicalactiontype", | ||
| options={ | ||
| "get_latest_by": ("history_date", "history_id"), | ||
| "ordering": ("-history_date", "-history_id"), | ||
| "verbose_name": "historical action type", | ||
| "verbose_name_plural": "historical action types", | ||
| }, | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name="historicalactiontype", | ||
| index=models.Index( | ||
| fields=["history_date", "id"], | ||
| name="route_manag_history_ee6aeb_idx", | ||
| ), | ||
| ), | ||
| # HistoricalEntry | ||
| migrations.AlterModelOptions( | ||
| name="historicalentry", | ||
| options={ | ||
| "get_latest_by": ("history_date", "history_id"), | ||
| "ordering": ("-history_date", "-history_id"), | ||
| "verbose_name": "historical entry", | ||
| "verbose_name_plural": "historical Entries", | ||
| }, | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name="historicalentry", | ||
| index=models.Index( | ||
| fields=["history_date", "id"], | ||
| name="route_manag_history_0a19f0_idx", | ||
| ), | ||
| ), | ||
| # HistoricalIgnoreEntry | ||
| migrations.AlterModelOptions( | ||
| name="historicalignoreentry", | ||
| options={ | ||
| "get_latest_by": ("history_date", "history_id"), | ||
| "ordering": ("-history_date", "-history_id"), | ||
| "verbose_name": "historical ignore entry", | ||
| "verbose_name_plural": "historical Ignored Entries", | ||
| }, | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name="historicalignoreentry", | ||
| index=models.Index( | ||
| fields=["history_date", "id"], | ||
| name="route_manag_history_6909c5_idx", | ||
| ), | ||
| ), | ||
| ] |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see why this is bad, but does it suggest we don't need to use WhoFilter anymore? I think I liked testing WhoFilter directly instead of testing the same thing in a different way. I do think we want to keep it since it's what is used on the admin panel to allow you to filter the list based on the user who added the entry. Maybe I'm overthinking it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| from rest_framework import status | ||
| from rest_framework.test import APITestCase | ||
|
|
||
| from scram.route_manager.models import Client | ||
| from scram.route_manager.models import ActionType, Client | ||
|
|
||
|
|
||
| class TestAddRemoveIP(APITestCase): | ||
|
|
@@ -16,12 +16,16 @@ def setUp(self): | |
| self.url = reverse("api:v1:entry-list") | ||
| self.superuser = get_user_model().objects.create_superuser("admin", "admin@es.net", "admintestpassword") | ||
| self.client.login(username="admin", password="admintestpassword") | ||
|
|
||
| # Create the ActionType | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block actiontype is created by default in one of the early migrations. We can depend on it existing, but maybe this is a case of "better to be explicit" |
||
| self.actiontype, _ = ActionType.objects.get_or_create(name="block") | ||
|
|
||
| self.authorized_client = Client.objects.create( | ||
| hostname="authorized_client.es.net", | ||
| uuid="0e7e1cbd-7d73-4968-bc4b-ce3265dc2fd3", | ||
| is_authorized=True, | ||
| ) | ||
| self.authorized_client.authorized_actiontypes.set([1]) | ||
| self.authorized_client.authorized_actiontypes.set([self.actiontype]) | ||
|
|
||
| def test_block_ipv4(self): | ||
| """Block a v4 IP.""" | ||
|
|
@@ -102,6 +106,9 @@ def setUp(self): | |
| self.entry_url = reverse("api:v1:entry-list") | ||
| self.ignore_url = reverse("api:v1:ignoreentry-list") | ||
|
|
||
| # Create the ActionType that the API endpoint will try to look up | ||
| ActionType.objects.get_or_create(name="block") | ||
|
|
||
| def test_unauthenticated_users_have_no_create_access(self): | ||
| """Ensure an unauthenticated client can't add an Entry.""" | ||
| response = self.client.post( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were we able to simplify so much? This seems much less brittle which is great, but are we looking at any side effects? We were conditionally doing this before so was that just not required?