Skip to content

Commit 4a4d1ab

Browse files
Fix run selection issue (#396)
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 6b38ad0 commit 4a4d1ab

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

.changeset/silver-baths-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trackio": patch
3+
---
4+
5+
feat:Fix run selection issue

tests/unit/test_sqlite_storage.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,34 @@ def test_old_database_without_configs_table(temp_dir):
232232

233233
all_configs = SQLiteStorage.get_all_run_configs("test")
234234
assert all_configs == {}
235+
236+
237+
def test_get_runs_returns_chronological_order(temp_dir):
238+
db_path = SQLiteStorage.get_project_db_path("proj")
239+
db_path.parent.mkdir(parents=True, exist_ok=True)
240+
241+
with sqlite3.connect(db_path) as conn:
242+
conn.execute("""
243+
CREATE TABLE metrics (
244+
id INTEGER PRIMARY KEY,
245+
timestamp TEXT,
246+
run_name TEXT,
247+
step INTEGER,
248+
metrics TEXT
249+
)
250+
""")
251+
conn.execute(
252+
"INSERT INTO metrics (timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?)",
253+
("2024-01-01", "run-z", 0, orjson.dumps({"loss": 0.5})),
254+
)
255+
conn.execute(
256+
"INSERT INTO metrics (timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?)",
257+
("2024-01-02", "run-a", 0, orjson.dumps({"loss": 0.5})),
258+
)
259+
conn.execute(
260+
"INSERT INTO metrics (timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?)",
261+
("2024-01-03", "run-m", 0, orjson.dumps({"loss": 0.5})),
262+
)
263+
264+
runs = SQLiteStorage.get_runs("proj")
265+
assert runs == ["run-z", "run-a", "run-m"]

trackio/sqlite_storage.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,20 @@ def get_projects() -> list[str]:
734734

735735
@staticmethod
736736
def get_runs(project: str) -> list[str]:
737-
"""Get list of all runs for a project."""
737+
"""Get list of all runs for a project, ordered by creation time."""
738738
db_path = SQLiteStorage.get_project_db_path(project)
739739
if not db_path.exists():
740740
return []
741741

742742
with SQLiteStorage._get_connection(db_path) as conn:
743743
cursor = conn.cursor()
744744
cursor.execute(
745-
"SELECT DISTINCT run_name FROM metrics",
745+
"""
746+
SELECT run_name
747+
FROM metrics
748+
GROUP BY run_name
749+
ORDER BY MIN(timestamp) ASC
750+
""",
746751
)
747752
return [row[0] for row in cursor.fetchall()]
748753

0 commit comments

Comments
 (0)