Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions api/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.http import Http404
from django.shortcuts import get_object_or_404 as _get_object_or_404


def get_object_or_404(*args, **kwargs):
"""Wrapper that returns 404 for invalid PK types (e.g. non-numeric IDs)."""
try:
return _get_object_or_404(*args, **kwargs)
except (ValueError, TypeError):
raise Http404
2 changes: 1 addition & 1 deletion api/views/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from core.models import Config
from django.core.files import File
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import ApiResponse, QueryOrBody, api_view
from users.services import IdentityService
from users.shortcuts import by_handle_or_404
Expand Down
2 changes: 1 addition & 1 deletion api/views/announcements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import api_view

from api import schemas
Expand Down
2 changes: 1 addition & 1 deletion api/views/conversations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404

from activities.models.conversation import Conversation, ConversationMembership
from activities.services import TimelineService
Expand Down
2 changes: 1 addition & 1 deletion api/views/follow_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import api_view

from api import schemas
Expand Down
2 changes: 1 addition & 1 deletion api/views/lists.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Literal

from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import Schema, api_view

from api import schemas
Expand Down
2 changes: 1 addition & 1 deletion api/views/media.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mimetypes

from django.core.files import File
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import ApiError, QueryOrBody, api_view

from activities.models import PostAttachment, PostAttachmentStates
Expand Down
2 changes: 1 addition & 1 deletion api/views/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from activities.models import PostInteraction, TimelineEvent
from activities.services import TimelineService
from django.http import Http404, HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import ApiResponse, QueryOrBody, api_view

from api import schemas
Expand Down
2 changes: 1 addition & 1 deletion api/views/polls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import Http404
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from hatchway import api_view, QueryOrBody

from activities.models import Post, PostInteraction
Expand Down
2 changes: 1 addition & 1 deletion api/views/push.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.http import Http404
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404

from api import schemas
from api.decorators import scope_required
Expand Down
2 changes: 1 addition & 1 deletion api/views/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404

from activities.models import Post
from api import schemas
Expand Down
2 changes: 1 addition & 1 deletion api/views/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.db.models import Q
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from django.utils import timezone
from pydantic import ConfigDict

Expand Down
2 changes: 1 addition & 1 deletion api/views/tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404
from django.utils import timezone

from activities.models import FanOut, Hashtag, Post
Expand Down
2 changes: 1 addition & 1 deletion api/views/timelines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from api.views import get_object_or_404

from activities.models import Post, TimelineEvent
from activities.services import TimelineService
Expand Down
2 changes: 1 addition & 1 deletion core/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def signed_request(
method == "post"
and response.status_code >= 400
and response.status_code < 500
and response.status_code != 404
and response.status_code not in [404, 410]
):
raise ValueError(
f"POST error to {uri}: {response.status_code} {response.content!r}"
Expand Down
6 changes: 2 additions & 4 deletions users/models/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,11 @@ def handle_undo_ap(cls, data):
"""
Handles an incoming Block Undo
"""
# Resolve source and target and see if a Follow exists (it hopefully does)
try:
block = cls.by_ap(data["object"])
except KeyError:
raise ValueError("No Block locally for incoming Undo", data)
except (KeyError, cls.DoesNotExist):
return
# Check the block's source is the actor
if data["actor"] != block.source.actor_uri:
raise ValueError("Undo actor does not match its Block object", data)
# Delete the follow
block.delete()
2 changes: 1 addition & 1 deletion users/models/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def fetch_nodeinfo(self) -> NodeInfo | None:
):
nodeinfo20_url = link.get("href", nodeinfo20_url)
break
except (json.JSONDecodeError, AttributeError):
except (json.JSONDecodeError, AttributeError, UnicodeDecodeError):
pass

try:
Expand Down
Loading