diff --git a/x-pack/plugins/task_manager/server/task_validator.test.ts b/x-pack/plugins/task_manager/server/task_validator.test.ts index 52822adf6f49f..08c18591e468e 100644 --- a/x-pack/plugins/task_manager/server/task_validator.test.ts +++ b/x-pack/plugins/task_manager/server/task_validator.test.ts @@ -64,9 +64,7 @@ describe('TaskValidator', () => { expect(result).toEqual(task); }); - // TODO: Remove skip once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - it.skip(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { + it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { const definitions = new TaskTypeDictionary(mockLogger()); definitions.registerTaskDefinitions({ foo: fooTaskDefinition, @@ -322,9 +320,7 @@ describe('TaskValidator', () => { expect(result).toEqual(task); }); - // TODO: Remove skip once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - it.skip(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { + it(`should fail to validate the state schema when the task type doesn't have stateSchemaByVersion defined`, () => { const definitions = new TaskTypeDictionary(mockLogger()); definitions.registerTaskDefinitions({ foo: fooTaskDefinition, diff --git a/x-pack/plugins/task_manager/server/task_validator.ts b/x-pack/plugins/task_manager/server/task_validator.ts index 61d9a903dd5b4..900af04cd1207 100644 --- a/x-pack/plugins/task_manager/server/task_validator.ts +++ b/x-pack/plugins/task_manager/server/task_validator.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { max, memoize } from 'lodash'; +import { max, memoize, isEmpty } from 'lodash'; import type { Logger } from '@kbn/core/server'; import type { ObjectType } from '@kbn/config-schema'; import { TaskTypeDictionary } from './task_type_dictionary'; @@ -64,14 +64,13 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); - // TODO: Remove once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - // Otherwise, failures on read / write would occur. (don't forget to unskip test) - if (!latestStateSchema) { + let state = task.state; + + // Skip validating tasks that don't use state + if (!latestStateSchema && isEmpty(state)) { return task; } - let state = task.state; try { state = this.getValidatedStateSchema( this.migrateTaskState(task.state, task.stateVersion, taskTypeDef, latestStateSchema), @@ -111,10 +110,8 @@ export class TaskValidator { const taskTypeDef = this.definitions.get(task.taskType); const latestStateSchema = this.cachedGetLatestStateSchema(taskTypeDef); - // TODO: Remove once all task types have defined their state schema. - // https://github.com/elastic/kibana/issues/159347 - // Otherwise, failures on read / write would occur. (don't forget to unskip test) - if (!latestStateSchema) { + // Skip validating tasks that don't use state + if (!latestStateSchema && isEmpty(task.state)) { return task; }