{"record":{"id":"81c4284dceacbd62","repo":"mlflow/mlflow","slug":"failed-to-construct-request-uri-for-get-latest-ver","errorCode":null,"errorMessage":"Failed to construct request URI for get latest versions.","messagePattern":"Failed to construct request URI for get latest versions\\.","errorType":"exception","errorClass":"MlflowClientException","httpStatus":null,"severity":"error","filePath":"mlflow/java/client/src/main/java/org/mlflow/tracking/MlflowProtobufMapper.java","lineNumber":136,"sourceCode":"\n  String makeRestoreRun(String runId) {\n    RestoreRun.Builder builder = RestoreRun.newBuilder();\n    builder.setRunId(runId);\n    return print(builder);\n  }\n\n  String makeGetLatestVersion(String modelName, Iterable<String> stages) {\n    try {\n      URIBuilder builder = new URIBuilder(\"registered-models/get-latest-versions\")\n              .addParameter(\"name\", modelName);\n      if (stages != null) {\n        for( String stage: stages) {\n          builder.addParameter(\"stages\", stage);\n        }\n      }\n      return builder.build().toString();\n    } catch (URISyntaxException e) {\n      throw new MlflowClientException(\"Failed to construct request URI for get latest versions.\",\n              e);\n    }\n  }\n\n  String makeUpdateModelVersion(String modelName, String version) {\n    return print(UpdateModelVersion.newBuilder().setName(modelName).setVersion(version));\n  }\n\n  String makeTransitionModelVersionStage(String modelName, String version, String stage) {\n    return print(TransitionModelVersionStage.newBuilder()\n            .setName(modelName).setVersion(version).setStage(stage));\n  }\n\n  String makeCreateModel(String modelName) {\n    CreateRegisteredModel.Builder builder = CreateRegisteredModel.newBuilder()\n            .setName(modelName);\n    return print(builder);\n  }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/java/client/src/main/java/org/mlflow/tracking/MlflowProtobufMapper.java#L118-L154","documentation":"makeGetLatestVersions builds the 'model-versions/get-latest-versions' query URI with URIBuilder and wraps any URISyntaxException into MlflowClientException. In practice this fires when building the URI fails, almost always due to illegal characters in a parameter value that URIBuilder cannot encode in this context.","triggerScenarios":"Calling getLatestVersions (via MlflowClient.getLatestVersions/downloadLatestModelVersion) when the resulting URI construction throws URISyntaxException — e.g. model name or stage containing characters the URIBuilder rejects for the request path/parameters.","commonSituations":"Model names containing spaces, slashes, or other special characters that were never valid registry names; corrupted stage or name strings from config/env; copying names with trailing whitespace or hidden characters from a UI or file.","solutions":["Check the model name and stage strings for illegal characters (spaces, '/', '?', control chars) and sanitize them.","Use a registry-compliant model name (alphanumerics, dashes, underscores, dots).","If the exception persists, capture the chained URISyntaxException (it is attached as the cause) for the exact parse error.","Retry the call with a plain ASCII name to isolate which parameter breaks URI construction."],"exampleFix":"// before\nclient.getLatestVersions(\"my model/v2\", Lists.newArrayList(\"Production\"));\n// after\nclient.getLatestVersions(\"my-model-v2\", Lists.newArrayList(\"Production\"));","handlingStrategy":"validation","validationCode":"static String sanitizeModelName(String name) {\n  String trimmed = name == null ? \"\" : name.trim();\n  if (!trimmed.matches(\"[A-Za-z0-9_.-]+\")) {\n    throw new IllegalArgumentException(\"Model name has URI-illegal characters: \" + trimmed);\n  }\n  return trimmed;\n}\n// use: client.getLatestVersions(sanitizeModelName(rawName), stages)","typeGuard":"static boolean isUriSafeParam(String value) {\n  return value != null && value.matches(\"[A-Za-z0-9_.\\- ]*\") && !value.contains(\"/\");\n}","tryCatchPattern":"try {\n  return client.getLatestVersions(modelName, stages);\n} catch (MlflowClientException e) {\n  if (e.getMessage().contains(\"Failed to construct request URI\")) {\n    throw new IllegalArgumentException(\"Check model name/stage for illegal URI characters: \" + modelName, e.getCause());\n  }\n  throw e;\n}","preventionTips":["Validate model names against [A-Za-z0-9_.-] before any registry call.","Trim whitespace and strip hidden characters when loading names from files/env.","Log the full exception cause (URISyntaxException) to see the exact offending character.","Prefer UTF-8 URL encoding at your own boundary instead of passing raw strings."],"tags":["java","uri","model-registry"],"backgroundTag":"uri-construction-failed","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}