{"record":{"id":"94c687679f057685","repo":"flowable/flowable-engine","slug":"latest-can-only-be-used-together-with-a-deployment","errorCode":null,"errorMessage":"latest can only be used together with a deployment key","messagePattern":"latest can only be used together with a deployment key","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/repository/AppDeploymentQueryImpl.java","lineNumber":147,"sourceCode":"    @Override\n    public AppDeploymentQueryImpl deploymentTenantIdLike(String tenantIdLike) {\n        if (tenantIdLike == null) {\n            throw new FlowableIllegalArgumentException(\"deploymentTenantIdLike is null\");\n        }\n        this.tenantIdLike = tenantIdLike;\n        return this;\n    }\n\n    @Override\n    public AppDeploymentQueryImpl deploymentWithoutTenantId() {\n        this.withoutTenantId = true;\n        return this;\n    }\n\n    @Override\n    public AppDeploymentQueryImpl latest() {\n        if (key == null) {\n            throw new FlowableIllegalArgumentException(\"latest can only be used together with a deployment key\");\n        }\n\n        this.latest = true;\n        return this;\n    }\n\n    // sorting ////////////////////////////////////////////////////////\n\n    @Override\n    public AppDeploymentQuery orderByDeploymentId() {\n        return orderBy(AppDeploymentQueryProperty.DEPLOYMENT_ID);\n    }\n\n    @Override\n    public AppDeploymentQuery orderByDeploymentTime() {\n        return orderBy(AppDeploymentQueryProperty.DEPLOY_TIME);\n    }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/repository/AppDeploymentQueryImpl.java#L129-L165","documentation":"AppDeploymentQueryImpl.latest() throws FlowableIllegalArgumentException when no deployment key has been set on the query. 'latest' means 'pick the newest deployment for a given key', so it is only meaningful in combination with deploymentKey(...). Calling latest() on a key-less query would be ambiguous and is rejected.","triggerScenarios":"Calling appDeploymentService.createDeploymentQuery().latest() without a preceding deploymentKey(\"someKey\") call.","commonSituations":"Upgrading auto-deployment logic that wants the newest version of an app definition; copying query code from an example that set a key in a removed line; misunderstanding latest() as a global 'latest deployments' flag.","solutions":["Call deploymentKey(...) before latest() so the query has a key to resolve the latest deployment for","If you want all deployments ordered by deployment time, sort by deploymentTime desc instead of using latest()","Remove the latest() call if you did not intend key-scoped latest-version semantics"],"exampleFix":"// before\nAppDeployment d = appDeploymentService.createDeploymentQuery().latest().singleResult();\n// after\nAppDeployment d = appDeploymentService.createDeploymentQuery()\n    .deploymentKey(\"myApp\")\n    .latest()\n    .singleResult();","handlingStrategy":"validation","validationCode":"if (useLatest) {\n    if (deploymentKey == null) {\n        throw new IllegalArgumentException(\"latest() requires deploymentKey to be set\");\n    }\n    query.deploymentKey(deploymentKey).latest();\n}","typeGuard":"boolean canUseLatest = deploymentKey != null && useLatest;","tryCatchPattern":"try {\n    query.latest();\n} catch (FlowableIllegalArgumentException e) {\n    throw new IllegalStateException(\"latest() used without deploymentKey — set the key first\", e);\n}","preventionTips":["Always pair latest() with deploymentKey(...) in a builder helper","Document that latest() is key-scoped, not a global flag","Write an integration test for the latest-version lookup path"],"tags":["invalid-query","flowable","precondition"],"backgroundTag":"conflicting-config-options","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}