Skip to content

Commit 01079a5

Browse files
Prachi194agrawalpre-commit-ci[bot]PGijsbers
authored
Fix: Use UserWarning for unauthenticated duplicate run checks (Fixes #1210) (#1484)
### Description This PR fixes #1210 by improving the warning message when `avoid_duplicate_runs=True` is used without an API key. **Changes:** - Replaced the generic `RuntimeWarning` with a `UserWarning`. - Updated the warning message to explicitly inform the user that duplicate runs cannot be checked server-side without authentication. - Changed the condition check to explicitly look for `openml.config.apikey is None`. ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) ### How Has This Been Tested? I verified this locally by mocking `openml.runs.run_model_on_task` with `apikey=None` and asserting that the new `UserWarning` is triggered correctly. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Pieter Gijsbers <p.gijsbers@tue.nl>
1 parent 496ac32 commit 01079a5

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎openml/runs/functions.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,14 @@ def run_model_on_task( # noqa: PLR0913,PLR0917
341341
"""
342342
if avoid_duplicate_runs is None:
343343
avoid_duplicate_runs = openml.config.avoid_duplicate_runs
344-
if avoid_duplicate_runs and not openml.config.apikey:
344+
if avoid_duplicate_runs and openml.config.apikey is None:
345345
warnings.warn(
346-
"avoid_duplicate_runs is set to True, but no API key is set. "
347-
"Please set your API key in the OpenML configuration file, see"
348-
"https://openml.github.io/openml-python/main/examples/20_basic/introduction_tutorial"
349-
".html#authentication for more information on authentication.",
350-
RuntimeWarning,
346+
"The 'avoid_duplicate_runs' parameter is set to True, but no API key is configured. "
347+
"Duplicate runs cannot be checked server-side without authentication. "
348+
"Please set your API key (for instructions, see "
349+
"http://openml.github.io/openml-python/latest/examples/Basics/introduction_tutorial/)."
350+
"The run will proceed, but duplicates may be created.",
351+
UserWarning,
351352
stacklevel=2,
352353
)
353354

0 commit comments

Comments
 (0)