Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when importing a file with file containing only excluded saved objects #103517

Closed
ymao1 opened this issue Jun 28, 2021 · 5 comments
Closed
Labels
bug Fixes for quality problems that affect the customer experience Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@ymao1
Copy link
Contributor

ymao1 commented Jun 28, 2021

With the recently added ability to filter out items onExport, it is possible to export an ndjson file that only contains "excluded" saved objects. If that file is then imported, the following error occurs:

Unhandled Promise rejection detected:

TypeError: Cannot destructure property 'title' of 'obj.attributes' as it is undefined.
    at /Users/ymao/Code/kibana/src/core/server/saved_objects/import/lib/collect_saved_objects.ts:47:15
    at Transform.transform [as _transform] (/Users/ymao/Code/kibana/node_modules/packages/kbn-utils/src/streams/filter_stream.ts:15:33)
    at Transform._read (internal/streams/transform.js:205:10)
    at Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Transform.Writable.write (internal/streams/writable.js:303:10)
    at Transform.ondata (internal/streams/readable.js:745:22)
    at Transform.emit (events.js:376:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Transform.Readable.push (internal/streams/readable.js:223:10)
    at Transform.push (internal/streams/transform.js:166:32)
    at Transform.done (internal/streams/transform.js:101:10)
    at Transform.transform [as _transform] (/Users/ymao/Code/kibana/src/core/server/saved_objects/import/lib/create_limit_stream.ts:21:7)
    at Transform._read (internal/streams/transform.js:205:10)
    at Transform._write (internal/streams/transform.js:193:12)

and the UI shows the following:

Screen Shot 2021-06-28 at 1 23 19 PM

In this case, my ndjson contained a single line:

{"excludedObjects":[{"id":"2a16ac09-d834-11eb-b614-2b1b222c1719","reason":"excluded","type":"alert"}],"excludedObjectsCount":1,"exportedCount":0,"missingRefCount":0,"missingReferences":[]}
@ymao1 ymao1 added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Jun 28, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@ymao1 ymao1 added the bug Fixes for quality problems that affect the customer experience label Jun 28, 2021
@ymao1
Copy link
Contributor Author

ymao1 commented Jun 28, 2021

It is erroring here:

const collectedObjects: Array<SavedObject<{ title?: string }>> = await createPromiseFromStreams([
readStream,
createLimitStream(objectLimit),
createFilterStream<SavedObject<{ title: string }>>((obj) => {
entries.push({ type: obj.type, id: obj.id });
if (supportedTypes.includes(obj.type)) {
return true;
}
const { title } = obj.attributes;
errors.push({
id: obj.id,
type: obj.type,
title,
meta: { title },
error: {
type: 'unsupported_type',
},
});
return false;
}),
createFilterStream<SavedObject>((obj) => (filter ? filter(obj) : true)),
createMapStream((obj: SavedObject) => {
importIdMap.set(`${obj.type}:${obj.id}`, {});
// Ensure migrations execute on every saved object
return Object.assign({ migrationVersion: {} }, obj);
}),
createConcatStream([]),
]);

because it can't destructure title from obj.attributes on line 47.

If I add

createFilterStream<SavedObject>((obj) => !!obj.id),

to line 42 to filter out entries without an id, I end up with a "successful" import and this in the UI:

Screen Shot 2021-06-28 at 3 47 46 PM

If that's ok for a short term fix, I will add it to my PR

cc @pgayvallet

@pgayvallet
Copy link
Contributor

createFilterStream<SavedObject | SavedObjectsExportResultDetails>(
(obj) => !!obj && !(obj as SavedObjectsExportResultDetails).exportedCount
),

This condition is buggy when exportCount is 0, causing the export detail line to be considered as a SO line.

It should be replaced by

(obj) => !!obj && (obj as SavedObjectsExportResultDetails).exportedCount === undefined

@TinaHeiligers
Copy link
Contributor

TinaHeiligers commented Jun 28, 2021

@pgayvallet I used your recommendation in #103573 but before realizing you folks had come to a resolution already. I'll close that draft if the fix is in another PR.

@ymao1
Copy link
Contributor Author

ymao1 commented Jun 28, 2021

Fix included in this PR: #102999 in these commits:

Thanks @pgayvallet and @TinaHeiligers for figuring out the bug fix & writing the test and letting me include it in my PR <3

@ymao1 ymao1 closed this as completed Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants