Skip to content

Commit 64ab9c6

Browse files
authored
Merge pull request #3693 from rommapp/posthog-code/fix-platform-variant-rename
fix(platforms): stop platform variants from renaming the parent platform
2 parents a750e3e + e61d6cd commit 64ab9c6

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from handler.database import db_platform_handler
2+
from models.platform import Platform
3+
from utils.platforms import get_supported_platforms
4+
5+
6+
def test_supported_platform_not_shadowed_by_variant():
7+
"""A variant/alias folder bound to a parent slug must not shadow the parent.
8+
9+
Regression for the bug where adding an "fbneo" folder as a variant of
10+
"arcade" renamed the Arcade platform to "FBneo" in the platform picker.
11+
"""
12+
# Canonical Arcade platform (folder name matches the slug).
13+
db_platform_handler.add_platform(
14+
Platform(name="Arcade", slug="arcade", fs_slug="arcade")
15+
)
16+
# Variant folder resolved to the same slug during scan.
17+
db_platform_handler.add_platform(
18+
Platform(name="FBneo", slug="arcade", fs_slug="fbneo")
19+
)
20+
21+
supported = get_supported_platforms()
22+
arcade = next(p for p in supported if p.slug == "arcade")
23+
24+
assert arcade.name == "Arcade"
25+
assert arcade.fs_slug == "arcade"

backend/utils/platforms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ def get_supported_platforms() -> list[PlatformSchema]:
2626
Flashpoint, and HowLongToBeat.
2727
"""
2828
db_platforms = db_platform_handler.get_platforms()
29-
db_platforms_map = {p.slug: p for p in db_platforms}
29+
30+
# Multiple folders can resolve to the same slug (a folder alias or a
31+
# platform variant bound to a parent platform). When that happens, prefer
32+
# the canonical platform (the one whose fs_slug matches its slug) so a
33+
# variant folder doesn't shadow the parent and rename it in the picker.
34+
db_platforms_map: dict[str, Platform] = {}
35+
for p in db_platforms:
36+
existing = db_platforms_map.get(p.slug)
37+
if existing is None or p.fs_slug == p.slug:
38+
db_platforms_map[p.slug] = p
3039

3140
now = datetime.now(timezone.utc)
3241
supported_platforms = []

0 commit comments

Comments
 (0)