alibaba/spring-ai-alibaba · error · IllegalStateException
Cannot delete published version:
Error message
Cannot delete published version:
What it means
deleteById() refuses to delete versions whose status is PUBLISHED, throwing IllegalStateException("Cannot delete published version: " + id). This is a business-rule protection: published versions are considered immutable reference data and must be unpublished or archived through another workflow first.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetVersionServiceImpl.java:190
/**
* Delete dataset version by ID
*/
@Transactional
public void deleteById(Long id) {
log.info("Deleting dataset version: {}", id);
if (id == null) {
throw new IllegalArgumentException("Version ID cannot be null");
}
DatasetVersionDO existingVersion = datasetVersionMapper.selectById(id);
if (existingVersion == null) {
throw new IllegalArgumentException("Dataset version not found: " + id);
}
if ("PUBLISHED".equals(existingVersion.getStatus())) {
throw new IllegalStateException("Cannot delete published version: " + id);
}
int result = datasetVersionMapper.deleteById(id);
if (result <= 0) {
throw new RuntimeException("Failed to delete dataset version");
}
log.info("Dataset version deleted successfully: {}", id);
}
@Override
public PageResult<Experiment> getExperiments(DatasetExperimentsListRequest request) {
long offset = (request.getPageNumber() - 1L) * request.getPageSize();
List<ExperimentDO> experimentDOList = experimentMapper.selectByDatasetId(request.getDatasetId(), offset, request.getPageSize());
Integer totalCount = experimentMapper.selectCountByDatasetId(request.getDatasetId());
View on GitHub (pinned to f82da0b50f)
Solutions
- Change the version status away from PUBLISHED (e.g. via update with status ARCHIVED/DRAFT) before deleting.
- Filter the deletion set to exclude versions with status PUBLISHED.
- If policy allows, unpublish the version through the intended workflow, then retry the delete.
Example fix
// before
service.deleteById(publishedId); // IllegalStateException
// after
DatasetVersion v = service.getById(publishedId);
if ("PUBLISHED".equals(v.getStatus())) {
service.update(new DatasetVersionUpdateRequest(publishedId, null, "ARCHIVED"));
}
service.deleteById(publishedId); Defensive patterns
Strategy: validation
Validate before calling
DatasetVersion v = service.getById(id);
if (v != null && "PUBLISHED".equals(v.getStatus())) {
throw new IllegalStateException("unpublish or archive version " + id + " before deleting");
} Type guard
boolean isPublished(DatasetVersion v) { return v != null && "PUBLISHED".equals(v.getStatus()); } Try / catch
try {
service.deleteById(id);
} catch (IllegalStateException e) {
// surface 'unpublish first' guidance to the user
return ResponseEntity.status(HttpStatus.CONFLICT).body(Map.of("error", e.getMessage()));
} Prevention
- Filter deletion candidates by status != PUBLISHED.
- Implement an explicit unpublish/archive workflow before deletion.
- Return HTTP 409 (conflict) from controllers catching this error so clients understand the lifecycle rule.
When it happens
Trigger: Calling deleteById on a version row whose status column equals "PUBLISHED"; attempting bulk cleanup that includes published versions.
Common situations: Cleaning up old dataset versions after an evaluation cycle and hitting published baselines; scripts that iterate all versions without filtering status; API users unaware of the publication lifecycle.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/5999711b4c1a6953.
Report an issue: GitHub.