From 97ee0a9f85b71a53078df7c17235279584ad9f99 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 3 Feb 2022 17:02:01 +0000 Subject: [PATCH] Fix crash on game support update --- app/logic/game_support.py | 16 +++++++--------- app/models/packages.py | 8 ++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/logic/game_support.py b/app/logic/game_support.py index a8b2572e..389aa3db 100644 --- a/app/logic/game_support.py +++ b/app/logic/game_support.py @@ -111,9 +111,6 @@ class GameSupportResolver: self.checked_packages.add(key) - if len(history) >= 50: - raise LogicError(500, f"Too deep! {', '.join(history)}") - if package.type != PackageType.MOD: raise LogicError(500, "Got non-mod") @@ -128,7 +125,7 @@ class GameSupportResolver: else: retval.intersection_update(ret) if len(retval) == 0: - raise LogicError(500, f"Conflict! Supported games narrowed at {key}") + raise LogicError(500, f"Detected game support contradiction, {key} may not be compatible with any games") self.resolved_packages[key] = retval return retval @@ -147,14 +144,15 @@ class GameSupportResolver: retval = self.resolve(package, []) for game in retval: + assert game + lookup = previous_supported.pop(game, None) - if lookup: - if lookup.confidence == 0: - lookup.supports = True - db.session.merge(lookup) - else: + if lookup is None: support = PackageGameSupport(package, game) db.session.add(support) + elif lookup.confidence == 0: + lookup.supports = True + db.session.merge(lookup) for game, support in previous_supported.items(): if support.confidence == 0: diff --git a/app/models/packages.py b/app/models/packages.py index 90e7625e..67e84e0d 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -483,6 +483,12 @@ class Package(db.Model): return Package.query.filter(Package.name == parts[1], Package.author.has(username=parts[0])).first() + def __eq__(self, other): + return self.name == other.name and self.author_id == other.author_id + + def __hash__(self): + return hash((self.author_id, self.name)) + def getId(self): return "{}/{}".format(self.author.username, self.name) @@ -1091,6 +1097,8 @@ class PackageScreenshot(db.Model): "order": self.order, "title": self.title, "url": base_url + self.url, + "width": self.width, + "height": self.height, "approved": self.approved, "created_at": self.created_at.isoformat(), "is_cover_image": self.package.cover_image == self,