From e1b32999f01cca7938392e637e9b5ef8912b3720 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 7 Nov 2022 16:04:23 +0100 Subject: [PATCH] Fix confusion about User constructor --- lib/git_exporter.py | 2 +- lib/user.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/git_exporter.py b/lib/git_exporter.py index 80333d2..8736366 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -75,7 +75,7 @@ class GitExporter: for flat in left_to_commit: if flat.commit.userid not in users: - users[flat.commit.userid] = User(db, flat.commit.userid) + users[flat.commit.userid] = User.find(db, flat.commit.userid) flat.user = users[flat.commit.userid] logging.debug(f"USER {flat.user}") self.gc_cnt -= 1 diff --git a/lib/user.py b/lib/user.py index 2d2aa95..16a7ad3 100644 --- a/lib/user.py +++ b/lib/user.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from lib.db import DB + FAKE_ACCOUNTS = ( "unknown", "buildservice-autocommit", @@ -15,8 +19,10 @@ FAKE_ACCOUNTS = ( class User: - def __init__(self, db, userid) -> None: + @staticmethod + def find(db: DB, userid: str) -> User: row = User.lookup(db, userid) + self = User() self.userid = userid if row: (_, _, self.email, self.realname) = row @@ -27,6 +33,7 @@ class User: self.email = "null@suse.de" if not self.realname: self.realname = f"OBS User {userid}" + return self def parse(self, xml, userid): self.userid = userid