Make get_representative() atomic

This commit is contained in:
Adeodato Simó 2023-11-19 18:09:22 -03:00
parent 198c0037c6
commit 13374917f3
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -236,7 +236,7 @@ class ActivityObject:
omit = kwargs.get("omit", ())
data = self.__dict__.copy()
# recursively serialize
for (k, v) in data.items():
for k, v in data.items():
try:
if issubclass(type(v), ActivityObject):
data[k] = v.serialize()
@ -397,18 +397,14 @@ def resolve_remote_id(
def get_representative():
"""Get or create an actor representing the instance
to sign outgoing HTTP GET requests"""
username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}"
email = "bookwyrm@localhost"
try:
user = models.User.objects.get(username=username)
except models.User.DoesNotExist:
user = models.User.objects.create_user(
username=username,
email=email,
return models.User.objects.get_or_create(
username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}",
defaults=dict(
email="bookwyrm@localhost",
local=True,
localname=INSTANCE_ACTOR_USERNAME,
)
return user
),
)[0]
def get_activitypub_data(url):