Handle errors when a Post references an invalid ancestor (#417)
This commit is contained in:
parent
1f44e93518
commit
94fe247b17
|
@ -23,6 +23,7 @@ from activities.models.post_types import (
|
||||||
PostTypeDataDecoder,
|
PostTypeDataDecoder,
|
||||||
PostTypeDataEncoder,
|
PostTypeDataEncoder,
|
||||||
)
|
)
|
||||||
|
from core.exceptions import capture_message
|
||||||
from core.html import ContentRenderer, strip_html
|
from core.html import ContentRenderer, strip_html
|
||||||
from core.ld import (
|
from core.ld import (
|
||||||
canonicalise,
|
canonicalise,
|
||||||
|
@ -853,7 +854,12 @@ class Post(StatorModel):
|
||||||
try:
|
try:
|
||||||
parent = cls.by_object_uri(post.in_reply_to)
|
parent = cls.by_object_uri(post.in_reply_to)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
cls.ensure_object_uri(post.in_reply_to, reason=post.object_uri)
|
try:
|
||||||
|
cls.ensure_object_uri(post.in_reply_to, reason=post.object_uri)
|
||||||
|
except ValueError:
|
||||||
|
capture_message(
|
||||||
|
f"Cannot fetch ancestor of Post={post.pk}, ancestor_uri={post.in_reply_to}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
parent.calculate_stats()
|
parent.calculate_stats()
|
||||||
return post
|
return post
|
||||||
|
@ -905,8 +911,8 @@ class Post(StatorModel):
|
||||||
Sees if the post is in our local set, and if not, schedules a fetch
|
Sees if the post is in our local set, and if not, schedules a fetch
|
||||||
for it (in the background)
|
for it (in the background)
|
||||||
"""
|
"""
|
||||||
if not object_uri:
|
if not object_uri or "://" not in object_uri:
|
||||||
raise ValueError("No URI provided!")
|
raise ValueError("URI missing or invalid")
|
||||||
try:
|
try:
|
||||||
cls.by_object_uri(object_uri)
|
cls.by_object_uri(object_uri)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
|
@ -977,8 +983,10 @@ class Post(StatorModel):
|
||||||
Handles an internal fetch-request inbox message
|
Handles an internal fetch-request inbox message
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cls.by_object_uri(data["object"]["object"], fetch=True)
|
uri = data["object"]["object"]
|
||||||
except cls.DoesNotExist:
|
if "://" in uri:
|
||||||
|
cls.by_object_uri(uri, fetch=True)
|
||||||
|
except (cls.DoesNotExist, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
### OpenGraph API ###
|
### OpenGraph API ###
|
||||||
|
|
|
@ -5,6 +5,7 @@ from activities.models import (
|
||||||
PostStates,
|
PostStates,
|
||||||
TimelineEvent,
|
TimelineEvent,
|
||||||
)
|
)
|
||||||
|
from core.exceptions import capture_message
|
||||||
from users.models import Identity
|
from users.models import Identity
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +92,12 @@ class PostService:
|
||||||
reason = ancestor.object_uri
|
reason = ancestor.object_uri
|
||||||
ancestor = self.queryset().filter(object_uri=object_uri).first()
|
ancestor = self.queryset().filter(object_uri=object_uri).first()
|
||||||
if ancestor is None:
|
if ancestor is None:
|
||||||
Post.ensure_object_uri(object_uri, reason=reason)
|
try:
|
||||||
|
Post.ensure_object_uri(object_uri, reason=reason)
|
||||||
|
except ValueError:
|
||||||
|
capture_message(
|
||||||
|
f"Cannot fetch ancestor Post={self.post.pk}, ancestor_uri={object_uri}"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
if ancestor.state in [PostStates.deleted, PostStates.deleted_fanned_out]:
|
if ancestor.state in [PostStates.deleted, PostStates.deleted_fanned_out]:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue