[BUG] `search_logged_models` fails on the second page when `filter_string=""` or `order_by=[]` (SQL store)
[!WARNING] Before submitting a PR, please make sure that:
- A maintainer has triaged this issue and applied the
readylabel- This issue has no assignee
- No duplicate PR exists
PRs not meeting these requirements may be automatically closed.
Issues Policy acknowledgement
- I have read and agree to submit bug reports in accordance with the issues policy
Where did you encounter this bug?
Local machine
MLflow version
- Client: master (e7c8954, 3.16.2.dev0)
- Tracking server: none, SQLite backend store (
sqlite:///...)
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux (Ubuntu 24.04)
- Python version: 3.11.15
- SQLAlchemy 2.1.1
Describe the problem
With a SQL backend store, search_logged_models can't fetch a second page if it's called with an empty filter string or an empty order_by list. The first page comes back with a token, but passing that token back with exactly the same arguments raises:
MlflowException: Filter string in the page token does not match the requested filter string. Expected: . Found: None(or Order by in the page token does not match the requested order by. Expected: []. Found: None for order_by=[]).
mlflow.search_logged_models(...) pages through the results itself, so it raises as soon as more than 100 models match. MlflowClient.search_logged_models(..., page_token=...) fails on the second page.
Cause: SearchLoggedModelsPaginationToken.decode (mlflow/utils/search_utils.py) reads the stored values back as token.get("filter_string") or None / token.get("order_by") or None. validate() then compares them with the caller's un-normalized "" / [], so a request never matches its own token. The REST handler and the auth filter already normalize with filter or None before calling the store, so this only shows up when the client talks to the database directly (sqlite://, postgresql://, ...). The same values work everywhere else: filter_string="" means no filter on the first page and in the other search APIs.
Expected: the second page returns the remaining models, the same as with filter_string=None.
A minimal fix is to normalize the request the same way in validate() (filter_string = filter_string or None, order_by = order_by or None). I have it working locally, with a regression test in tests/store/tracking/sqlalchemy_store/test_sqlalchemy_store_runs.py that fails without the change.
Tracking information
Tracking URI: sqlite:///<tmp dir>/mlflow.db (client talks to the database directly, no tracking server)Code to reproduce issue
import tempfile
import mlflow
mlflow.set_tracking_uri(f"sqlite:///{tempfile.mkdtemp()}/mlflow.db")
exp_id = mlflow.set_experiment("logged-models").experiment_id
for i in range(101):
mlflow.initialize_logged_model(name=f"model-{i}", experiment_id=exp_id)
# Works: 101 models
print(len(mlflow.search_logged_models(experiment_ids=[exp_id], output_format="list")))
# Raises once the search needs a second page
mlflow.search_logged_models(experiment_ids=[exp_id], filter_string="", output_format="list")Stack trace
Traceback (most recent call last):
File "repro.py", line 13, in <module>
mlflow.search_logged_models(experiment_ids=[exp_id], filter_string="", output_format="list")
File "mlflow/tracking/fluent.py", line 3080, in search_logged_models
logged_models_page = client.search_logged_models(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mlflow/tracking/client.py", line 6099, in search_logged_models
return self._tracking_client.search_logged_models(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mlflow/tracking/_tracking_service/client.py", line 944, in search_logged_models
return self.store.search_logged_models(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mlflow/store/tracking/sqlalchemy_store.py", line 3804, in search_logged_models
token.validate(experiment_ids, filter_string, order_by)
File "mlflow/utils/search_utils.py", line 2750, in validate
raise MlflowException.invalid_parameter_value(
mlflow.exceptions.MlflowException: Filter string in the page token does not match the requested filter string. Expected: . Found: NoneOther info / logs
No response
Willingness to contribute
Yes. I can contribute a fix for this bug independently.
What component(s) does this bug affect?
-
area/tracking: Tracking Service, tracking client APIs, autologging -
area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry -
area/scoring: MLflow model serving, deployment tools, Spark UDFs -
area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows -
area/prompt: MLflow prompt engineering features, prompt templates, and prompt management -
area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality -
area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations -
area/projects: MLproject format, project running backends -
area/uiux: Front-end, user experience, plotting -
area/docs: MLflow documentation pages
Source: mlflow/mlflow