summaryrefslogtreecommitdiffstats
path: root/users
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-21 08:31:14 -0700
committerAndrew Godwin2022-11-21 14:31:16 -0700
commitcfae183e80c2147c65d09cf56f5cbe51fc574feb (patch)
tree604b073802b583bce42559e5e157b810ecbaa3d2 /users
parentc4be52357bb8d47c32ab6b2a80ae4ad7c5413f0f (diff)
downloadtakahe-cfae183e80c2147c65d09cf56f5cbe51fc574feb.tar.gz
takahe-cfae183e80c2147c65d09cf56f5cbe51fc574feb.tar.bz2
takahe-cfae183e80c2147c65d09cf56f5cbe51fc574feb.zip
Don't error fetching people if they're in the DB
Diffstat (limited to 'users')
-rw-r--r--users/models/identity.py16
-rw-r--r--users/tests/conftest.py2
2 files changed, 15 insertions, 3 deletions
diff --git a/users/models/identity.py b/users/models/identity.py
index dc2ee26..d7572d6 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -5,7 +5,7 @@ from urllib.parse import urlparse
import httpx
import urlman
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.templatetags.static import static
from django.utils import timezone
@@ -387,7 +387,19 @@ class Identity(StatorModel):
else:
self.domain = await get_domain(actor_url_parts.hostname)
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
### Cryptography ###
diff --git a/users/tests/conftest.py b/users/tests/conftest.py
index e1eeb4b..0b12793 100644
--- a/users/tests/conftest.py
+++ b/users/tests/conftest.py
@@ -44,7 +44,7 @@ kwIDAQAB
@pytest.fixture
-def config_system(db):
+def config_system():
Config.system = Config.SystemOptions(
system_actor_private_key=private_key, system_actor_public_key=public_key
)