Skip to content

Account.sharecode may yield outdated sharecode #51

Description

@kostrykin

Description of the bug:

When a user joins (aka create an account) in a situation where he has been already playing with the squad for a long time without having an account, it is likely that the Steam API endpoint refuses the old sharecode, that is determined in

@property
def sharecode(self):
# FIXME: `find_oldest_sharecode` should be the sharecode of a match,
# where this user participated, and not just any
return self.steam_profile.find_oldest_sharecode() if len(self.last_sharecode) == 0 else self.last_sharecode

In this case, a InvalidSharecodeError will be raised, and the account will be disabled from future updates in

cs2pb/django/stats/models.py

Lines 1313 to 1315 in 02a172f

except InvalidSharecodeError:
self.account.enabled = False
self.account.save()

because resolving the issue requires manual intervention (finding a sharecode that still works).

Proposed solution:

To fix the bug, a situation that requires manual intervention should not occur. When the InvalidSharecodeError is raised and the last_sharecode of the account is empty (i.e. the account has just been created and there hasn't been a successful update yet), instead of bluntly disabling the account, the code should repeat the code block

cs2pb/django/stats/models.py

Lines 1278 to 1315 in 02a172f

try:
first_sharecode = self.account.sharecode
new_match_data = api.fetch_matches(
first_sharecode,
SteamAPIUser(self.account.steamid, self.account.steam_auth),
)
old_participations = list(self.account.match_participations().order_by('pmatch__timestamp'))
for match_data in new_match_data:
fast_forward = False
try:
pmatch = Match.create_from_data(match_data)
except FileNotFoundError as ex:
if str(ex) == 'JSON path does not exist!':
# see: https://github.com/pnxenopoulos/awpy/issues/291
log.error(
f'Skipping match with sharecode {match_data["sharecode"]} due to error: '
f'https://github.com/pnxenopoulos/awpy/issues/291'
)
fast_forward = True
else:
raise
self.account.last_sharecode = match_data['sharecode']
self.account.save()
if fast_forward:
continue
participation = pmatch.get_participation(self.account.steam_profile)
MatchBadge.award_with_history(participation, old_participations)
old_participations.append(participation)
except InvalidSharecodeError:
self.account.enabled = False
self.account.save()

using a newer sharecode. Here, the sharecode is determined by self.account.sharecode, which is implemented as

@property
def sharecode(self):
# FIXME: `find_oldest_sharecode` should be the sharecode of a match,
# where this user participated, and not just any
return self.steam_profile.find_oldest_sharecode() if len(self.last_sharecode) == 0 else self.last_sharecode

and instead of just using the oldest sharecode, one should use the oldest sharecode that is still newer than one from the previous attempt.

Sidenote: The FIXME seems obsolete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendIssue concerning the backendbugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions