Filter saved object version during legacy import (#75597)

This commit is contained in:
Joe Portner 2020-08-21 14:30:25 -04:00 committed by GitHub
parent 5edba21e30
commit 68dc4e8410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -30,12 +30,18 @@ describe('importDashboards(req)', () => {
savedObjectClient.bulkCreate.mockResolvedValue({ saved_objects: [] });
importedObjects = [
{ id: 'dashboard-01', type: 'dashboard', attributes: { panelJSON: '{}' }, references: [] },
{
id: 'dashboard-01',
type: 'dashboard',
attributes: { panelJSON: '{}' },
references: [],
version: 'foo',
},
{ id: 'panel-01', type: 'visualization', attributes: { visState: '{}' }, references: [] },
];
});
test('should call bulkCreate with each asset', async () => {
test('should call bulkCreate with each asset, filtering out any version if present', async () => {
await importDashboards(savedObjectClient, importedObjects, { overwrite: false, exclude: [] });
expect(savedObjectClient.bulkCreate).toHaveBeenCalledTimes(1);

View file

@ -31,7 +31,8 @@ export async function importDashboards(
// docs are not seen as automatically up-to-date.
const docs = objects
.filter((item) => !exclude.includes(item.type))
.map((doc) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
// filter out any document version, if present
.map(({ version, ...doc }) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
const results = await savedObjectsClient.bulkCreate(docs, { overwrite });
return { objects: results.saved_objects };