Skip to content

Commit 4b0133a

Browse files
committed
fix(jobs): ignore invalid users stats
1 parent acd0809 commit 4b0133a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/jobs/record_usages.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,24 @@ async def get_users_stats(node: PasarGuardNode):
155155
params = defaultdict(int)
156156
for stat in filter(attrgetter("value"), stats_respons.stats):
157157
params[stat.name.split(".", 1)[0]] += stat.value
158-
params = list({"uid": int(uid), "value": value} for uid, value in params.items())
159-
return params
158+
159+
# Validate UIDs and filter out invalid ones
160+
validated_params = []
161+
for uid, value in params.items():
162+
try:
163+
uid_int = int(uid)
164+
validated_params.append({"uid": uid_int, "value": value})
165+
except (ValueError, TypeError):
166+
# Skip invalid UIDs that can't be converted to int
167+
logger.warning("Skipping invalid UID: %s", uid)
168+
continue
169+
170+
return validated_params
160171
except NodeAPIError as e:
161-
logger.error("Failed to get outbounds stats, error: %s", e.detail)
172+
logger.error("Failed to get users stats, error: %s", e.detail)
162173
return []
163174
except Exception as e:
164-
logger.error("Failed to get outbounds stats, unknown error: %s", e)
175+
logger.error("Failed to get users stats, unknown error: %s", e)
165176
return []
166177

167178

0 commit comments

Comments
 (0)