diff --git a/x-pack/plugins/ml/common/util/object_utils.test.ts b/x-pack/plugins/ml/common/util/object_utils.test.ts index f514cfd27ce2c..40ce0b27deae8 100644 --- a/x-pack/plugins/ml/common/util/object_utils.test.ts +++ b/x-pack/plugins/ml/common/util/object_utils.test.ts @@ -27,6 +27,6 @@ describe('object_utils', () => { 'attribute1', 'otherAttribute', ]) - ).toBe(true); + ).toBe(false); }); }); diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/util/filter_runtime_mappings.ts b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/util/filter_runtime_mappings.ts index e3e26d76cf6e7..5995224ef3254 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/util/filter_runtime_mappings.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/util/filter_runtime_mappings.ts @@ -22,8 +22,10 @@ interface Response { export function filterRuntimeMappings(job: Job, datafeed: Datafeed): Response { if ( - datafeed.runtime_mappings === undefined || - isPopulatedObject(datafeed.runtime_mappings) === false + !( + isPopulatedObject(datafeed, ['runtime_mappings']) && + isPopulatedObject(datafeed.runtime_mappings) + ) ) { return { runtime_mappings: {}, @@ -83,13 +85,10 @@ function findFieldsInJob(job: Job, datafeed: Datafeed) { return [...usedFields]; } -function findFieldsInAgg(obj: Record<string, object>) { +function findFieldsInAgg(obj: Record<string, unknown>) { const fields: string[] = []; Object.entries(obj).forEach(([key, val]) => { - if ( - isPopulatedObject<Record<string, object>>(val) && - Object.keys(val).every((d) => typeof d === 'object') - ) { + if (isPopulatedObject(val)) { fields.push(...findFieldsInAgg(val)); } else if (typeof val === 'string' && key === 'field') { fields.push(val); diff --git a/x-pack/plugins/transform/common/utils/object_utils.test.ts b/x-pack/plugins/transform/common/utils/object_utils.test.ts index 176b57a296dfa..fd0edeeb42a44 100644 --- a/x-pack/plugins/transform/common/utils/object_utils.test.ts +++ b/x-pack/plugins/transform/common/utils/object_utils.test.ts @@ -88,6 +88,6 @@ describe('object_utils', () => { 'attribute1', 'otherAttribute', ]) - ).toBe(true); + ).toBe(false); }); });