Fix crash on game support update

This commit is contained in:
rubenwardy 2022-02-03 17:02:01 +00:00
parent 958f92fd63
commit 97ee0a9f85
2 changed files with 15 additions and 9 deletions

@ -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:

@ -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,