From 2fe46c14ab2fdd317a704692f87584d35a3733ff Mon Sep 17 00:00:00 2001 From: Mike Rosseel Date: Sat, 18 Apr 2026 17:56:28 +0200 Subject: [PATCH] fix: preserve insertion order of object names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get_object_id_to_names query used list(set(...)) to deduplicate names, which produces non-deterministic order due to Python hash randomization. This caused Bright Star catalog entries (and others with multiple names) to display names in inconsistent order, varying between runs — e.g. "Str3 Alpha Crucis, Acrux" instead of the expected "Str3 Acrux, Alpha Crucis". Use dict.fromkeys() to deduplicate while preserving order, and add ORDER BY rowid to the query so SQLite returns names in insertion order. Co-Authored-By: Claude Opus 4.7 (1M context) --- python/PiFinder/db/objects_db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/PiFinder/db/objects_db.py b/python/PiFinder/db/objects_db.py index b52057f41..b8ad3b50f 100644 --- a/python/PiFinder/db/objects_db.py +++ b/python/PiFinder/db/objects_db.py @@ -194,7 +194,7 @@ def get_object_id_to_names(self) -> DefaultDict[int, List[str]]: logging.info("Starting get_object_id_to_names query...") query_start = time.time() - self.cursor.execute("SELECT object_id, common_name FROM names;") + self.cursor.execute("SELECT object_id, common_name FROM names ORDER BY rowid;") results = self.cursor.fetchall() query_time = time.time() - query_start logging.info( @@ -206,7 +206,7 @@ def get_object_id_to_names(self) -> DefaultDict[int, List[str]]: for object_id, common_name in results: name_dict[object_id].append(common_name.strip()) for object_id in name_dict: - name_dict[object_id] = list(set(name_dict[object_id])) + name_dict[object_id] = list(dict.fromkeys(name_dict[object_id])) process_time = time.time() - process_start logging.info( f"Processing took {process_time:.2f}s, created {len(name_dict)} object entries"