Don't error fetching people if they're in the DB
This commit is contained in:
parent
c4be52357b
commit
cfae183e80
@ -5,7 +5,7 @@ from urllib.parse import urlparse
|
|||||||
import httpx
|
import httpx
|
||||||
import urlman
|
import urlman
|
||||||
from asgiref.sync import async_to_sync, sync_to_async
|
from asgiref.sync import async_to_sync, sync_to_async
|
||||||
from django.db import models
|
from django.db import IntegrityError, models
|
||||||
from django.template.defaultfilters import linebreaks_filter
|
from django.template.defaultfilters import linebreaks_filter
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -387,7 +387,19 @@ class Identity(StatorModel):
|
|||||||
else:
|
else:
|
||||||
self.domain = await get_domain(actor_url_parts.hostname)
|
self.domain = await get_domain(actor_url_parts.hostname)
|
||||||
self.fetched = timezone.now()
|
self.fetched = timezone.now()
|
||||||
await sync_to_async(self.save)()
|
try:
|
||||||
|
await sync_to_async(self.save)()
|
||||||
|
except IntegrityError as e:
|
||||||
|
# See if we can fetch a PK and save there
|
||||||
|
if self.pk is None:
|
||||||
|
try:
|
||||||
|
other_row = await Identity.objects.aget(actor_uri=self.actor_uri)
|
||||||
|
except Identity.DoesNotExist:
|
||||||
|
raise ValueError(
|
||||||
|
f"Could not save Identity at end of actor fetch: {e}"
|
||||||
|
)
|
||||||
|
self.pk: Optional[int] = other_row.pk
|
||||||
|
await sync_to_async(self.save)()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
### Cryptography ###
|
### Cryptography ###
|
||||||
|
@ -44,7 +44,7 @@ kwIDAQAB
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config_system(db):
|
def config_system():
|
||||||
Config.system = Config.SystemOptions(
|
Config.system = Config.SystemOptions(
|
||||||
system_actor_private_key=private_key, system_actor_public_key=public_key
|
system_actor_private_key=private_key, system_actor_public_key=public_key
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user