[BUG] search_logged_models raises INTERNAL_ERROR for the "attributes." prefix on timestamp attributes
[!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 (
8fe97be06a8d690f6b012925db4db927104cb687) - Tracking server: same (SQLAlchemy backend,
sqlite://)
System information
- OS Platform and Distribution: macOS 15 (Darwin 25.6.0), arm64
- Python version: 3.11
Describe the problem
MlflowClient.search_logged_models documents two equivalent ways to name an attribute in filter_string:
- Entity specification:
- attributes:
attribute_name(default if no prefix is specified)
The two forms disagree for the aliased timestamp attributes. creation_time > 0 returns the matching models; the explicitly prefixed attributes.creation_time > 0 fails with an INTERNAL_ERROR (HTTP 500 through the REST server). The same applies to creation_timestamp and last_updated_timestamp, and to the backquoted bare form `creation_time` > 0.
Root cause is in Entity.from_str (mlflow/utils/search_logged_model_utils.py):
@classmethod
def from_str(cls, s: str) -> "Entity":
if m := Entity.IDENTIFIER_RE.match(s):
return cls(
type=EntityType.from_str(m.group(1)),
key=m.group(2).strip("`"), # <- no alias resolution
)
return cls(type=EntityType.ATTRIBUTE, key=SqlLoggedModel.ALIASES.get(s, s).strip("`"))SqlLoggedModel.ALIASES (creation_time/creation_timestamp -> creation_timestamp_ms, last_updated_timestamp -> last_updated_timestamp_ms) is applied only on the prefix-less branch. Note the second branch also looks up the alias before stripping backticks, so `creation_time` misses it too.
SqlAlchemyStore._apply_filter_string_datasets_search_logged_models then calls getattr(SqlLoggedModel, comp.entity.key) with the unresolved name and the AttributeError escapes as INTERNAL_ERROR.
Secondary effect of the same missing resolution step: any attribute name that is not a column (bogus = 'x') also produces INTERNAL_ERROR / HTTP 500 rather than a INVALID_PARAMETER_VALUE client error. The sibling code path for ordering, _apply_order_by_search_logged_models, already guards this case:
try:
col = getattr(SqlLoggedModel, name)
except AttributeError:
raise MlflowException.invalid_parameter_value(
f"Invalid order by field name: {field_name}", error_class="ATTRIBUTE_NOT_FOUND"
)Expected behavior: attributes.creation_time > 0 behaves identically to creation_time > 0, and an unknown attribute is rejected with INVALID_PARAMETER_VALUE.
Code to reproduce issue
import mlflow
mlflow.set_tracking_uri("sqlite:///mlflow-repro.db")
exp_id = mlflow.create_experiment("repro")
mlflow.create_external_model(experiment_id=exp_id, name="m1")
for f in ["creation_time > 0", "attributes.creation_time > 0"]:
try:
models = mlflow.search_logged_models(experiment_ids=[exp_id], filter_string=f)
print(f"{f!r:32} -> {len(models)} model(s)")
except Exception as e:
print(f"{f!r:32} -> {type(e).__name__}: {e}")Output on 8fe97be:
'creation_time > 0' -> 1 model(s)
'attributes.creation_time > 0' -> MlflowException: type object 'SqlLoggedModel' has no attribute 'creation_time'Stack trace
File "mlflow/store/tracking/sqlalchemy_store.py", line 3663, in search_logged_models
models = self._apply_filter_string_datasets_search_logged_models(
File "mlflow/store/tracking/sqlalchemy_store.py", line 3584, in _apply_filter_string_datasets_search_logged_models
attr_filters.append(comp_func(getattr(SqlLoggedModel, comp.entity.key), comp.value))
AttributeError: type object 'SqlLoggedModel' has no attribute 'creation_time'
The above exception was the direct cause of the following exception:
File "mlflow/tracking/fluent.py", line 3007, in search_logged_models
File "mlflow/tracking/client.py", line 6090, in search_logged_models
File "mlflow/tracking/_tracking_service/client.py", line 944, in search_logged_models
File "mlflow/store/tracking/sqlalchemy_store.py", line 3661, in search_logged_models
File "mlflow/store/db/utils.py", line 190, in make_managed_session
raise MlflowException(message=e, error_code=INTERNAL_ERROR) from e
mlflow.exceptions.MlflowException: type object 'SqlLoggedModel' has no attribute 'creation_time'Willingness to contribute
- Yes. I can contribute a fix for this bug independently. (A fix with regression tests is ready; I will open the PR once this issue is labelled
ready.)
What component(s) does this bug affect?
-
area/tracking: Tracking Service, tracking client APIs, autologging
Source: mlflow/mlflow