mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Merge pull request #3150 from dato/get_representative_atomic
Make get_representative() atomic
This commit is contained in:
commit
ffeca9f908
1 changed files with 7 additions and 11 deletions
|
@ -236,7 +236,7 @@ class ActivityObject:
|
||||||
omit = kwargs.get("omit", ())
|
omit = kwargs.get("omit", ())
|
||||||
data = self.__dict__.copy()
|
data = self.__dict__.copy()
|
||||||
# recursively serialize
|
# recursively serialize
|
||||||
for (k, v) in data.items():
|
for k, v in data.items():
|
||||||
try:
|
try:
|
||||||
if issubclass(type(v), ActivityObject):
|
if issubclass(type(v), ActivityObject):
|
||||||
data[k] = v.serialize()
|
data[k] = v.serialize()
|
||||||
|
@ -397,18 +397,14 @@ def resolve_remote_id(
|
||||||
def get_representative():
|
def get_representative():
|
||||||
"""Get or create an actor representing the instance
|
"""Get or create an actor representing the instance
|
||||||
to sign outgoing HTTP GET requests"""
|
to sign outgoing HTTP GET requests"""
|
||||||
username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}"
|
return models.User.objects.get_or_create(
|
||||||
email = "bookwyrm@localhost"
|
username=f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}",
|
||||||
try:
|
defaults=dict(
|
||||||
user = models.User.objects.get(username=username)
|
email="bookwyrm@localhost",
|
||||||
except models.User.DoesNotExist:
|
|
||||||
user = models.User.objects.create_user(
|
|
||||||
username=username,
|
|
||||||
email=email,
|
|
||||||
local=True,
|
local=True,
|
||||||
localname=INSTANCE_ACTOR_USERNAME,
|
localname=INSTANCE_ACTOR_USERNAME,
|
||||||
)
|
),
|
||||||
return user
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
def get_activitypub_data(url):
|
def get_activitypub_data(url):
|
||||||
|
|
Loading…
Reference in a new issue