mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
extensive logging for find_actor_or_create() issues
This commit is contained in:
parent
deb14b73f3
commit
cbd68f8fd8
1 changed files with 13 additions and 1 deletions
|
@ -263,19 +263,23 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
alt_user_name = actor_url.rsplit('/', 1)[-1]
|
alt_user_name = actor_url.rsplit('/', 1)[-1]
|
||||||
user = User.query.filter(or_(User.ap_profile_id == actor, User.alt_user_name == alt_user_name)).filter_by(ap_id=None, banned=False).first() # finds local users
|
user = User.query.filter(or_(User.ap_profile_id == actor, User.alt_user_name == alt_user_name)).filter_by(ap_id=None, banned=False).first() # finds local users
|
||||||
if user is None:
|
if user is None:
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): Local user not found for {actor}')
|
||||||
return None
|
return None
|
||||||
elif actor.startswith('https://'):
|
elif actor.startswith('https://'):
|
||||||
server, address = extract_domain_and_actor(actor)
|
server, address = extract_domain_and_actor(actor)
|
||||||
if get_setting('use_allowlist', False):
|
if get_setting('use_allowlist', False):
|
||||||
if not instance_allowed(server):
|
if not instance_allowed(server):
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): Instance not allowed for {actor}')
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if instance_blocked(server):
|
if instance_blocked(server):
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): Instance blocked for {actor}')
|
||||||
return None
|
return None
|
||||||
if actor_contains_blocked_words(actor):
|
if actor_contains_blocked_words(actor):
|
||||||
return None
|
return None
|
||||||
user = User.query.filter(User.ap_profile_id == actor).first() # finds users formatted like https://kbin.social/u/tables
|
user = User.query.filter(User.ap_profile_id == actor).first() # finds users formatted like https://kbin.social/u/tables
|
||||||
if (user and user.banned) or (user and user.deleted) :
|
if (user and user.banned) or (user and user.deleted):
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): User banned or deleted for {actor}')
|
||||||
return None
|
return None
|
||||||
if user is None:
|
if user is None:
|
||||||
user = Community.query.filter(Community.ap_profile_id == actor).first()
|
user = Community.query.filter(Community.ap_profile_id == actor).first()
|
||||||
|
@ -283,6 +287,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
# Try to find a non-banned copy of the community. Sometimes duplicates happen and one copy is banned.
|
# Try to find a non-banned copy of the community. Sometimes duplicates happen and one copy is banned.
|
||||||
user = Community.query.filter(Community.ap_profile_id == actor).filter(Community.banned == False).first()
|
user = Community.query.filter(Community.ap_profile_id == actor).filter(Community.banned == False).first()
|
||||||
if user is None: # no un-banned version of this community exists, only the banned one. So it was banned for being bad, not for being a duplicate.
|
if user is None: # no un-banned version of this community exists, only the banned one. So it was banned for being bad, not for being a duplicate.
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): Banned community for {actor}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if user is not None:
|
if user is not None:
|
||||||
|
@ -299,6 +304,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
refresh_community_profile(user.id)
|
refresh_community_profile(user.id)
|
||||||
# refresh_instance_profile(user.instance_id) # disable in favour of cron job - see app.cli.daily_maintenance()
|
# refresh_instance_profile(user.instance_id) # disable in favour of cron job - see app.cli.daily_maintenance()
|
||||||
if community_only and not isinstance(user, Community):
|
if community_only and not isinstance(user, Community):
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): User found instead of community {actor}')
|
||||||
return None
|
return None
|
||||||
return user
|
return user
|
||||||
else: # User does not exist in the DB, it's going to need to be created from it's remote home instance
|
else: # User does not exist in the DB, it's going to need to be created from it's remote home instance
|
||||||
|
@ -308,10 +314,12 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
try:
|
try:
|
||||||
actor_data = get_request(actor_url, headers={'Accept': 'application/activity+json'})
|
actor_data = get_request(actor_url, headers={'Accept': 'application/activity+json'})
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): http error {actor}, retrying...')
|
||||||
time.sleep(randint(3, 10))
|
time.sleep(randint(3, 10))
|
||||||
try:
|
try:
|
||||||
actor_data = get_request(actor_url, headers={'Accept': 'application/activity+json'})
|
actor_data = get_request(actor_url, headers={'Accept': 'application/activity+json'})
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): http error {actor}, giving up.')
|
||||||
raise e
|
raise e
|
||||||
return None
|
return None
|
||||||
if actor_data.status_code == 200:
|
if actor_data.status_code == 200:
|
||||||
|
@ -319,6 +327,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
actor_json = actor_data.json()
|
actor_json = actor_data.json()
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
actor_data.close()
|
actor_data.close()
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): json decoding error for {actor}')
|
||||||
return None
|
return None
|
||||||
actor_data.close()
|
actor_data.close()
|
||||||
actor_model = actor_json_to_model(actor_json, address, server)
|
actor_model = actor_json_to_model(actor_json, address, server)
|
||||||
|
@ -338,6 +347,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
return None
|
return None
|
||||||
return actor_model
|
return actor_model
|
||||||
except Exception:
|
except Exception:
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): exception doing signed request for {actor}')
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
# retrieve user details via webfinger, etc
|
# retrieve user details via webfinger, etc
|
||||||
|
@ -358,6 +368,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
try:
|
try:
|
||||||
actor_data = get_request(links['href'], headers={'Accept': type})
|
actor_data = get_request(links['href'], headers={'Accept': type})
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): http error {actor} during webfinger, retrying...')
|
||||||
time.sleep(randint(3, 10))
|
time.sleep(randint(3, 10))
|
||||||
actor_data = get_request(links['href'], headers={'Accept': type})
|
actor_data = get_request(links['href'], headers={'Accept': type})
|
||||||
# to see the structure of the json contained in actor_data, do a GET to https://lemmy.world/c/technology with header Accept: application/activity+json
|
# to see the structure of the json contained in actor_data, do a GET to https://lemmy.world/c/technology with header Accept: application/activity+json
|
||||||
|
@ -368,6 +379,7 @@ def find_actor_or_create(actor: str, create_if_not_found=True, community_only=Fa
|
||||||
if community_only and not isinstance(actor_model, Community):
|
if community_only and not isinstance(actor_model, Community):
|
||||||
return None
|
return None
|
||||||
return actor_model
|
return actor_model
|
||||||
|
current_app.logger.info(f'find_actor_or_create(): got to end, failed to find {actor}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue