Skip to content

Commit 68dc4e8

Browse files
authored
Filter saved object version during legacy import (#75597)
1 parent 5edba21 commit 68dc4e8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/plugins/legacy_export/server/lib/import/import_dashboards.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ describe('importDashboards(req)', () => {
3030
savedObjectClient.bulkCreate.mockResolvedValue({ saved_objects: [] });
3131

3232
importedObjects = [
33-
{ id: 'dashboard-01', type: 'dashboard', attributes: { panelJSON: '{}' }, references: [] },
33+
{
34+
id: 'dashboard-01',
35+
type: 'dashboard',
36+
attributes: { panelJSON: '{}' },
37+
references: [],
38+
version: 'foo',
39+
},
3440
{ id: 'panel-01', type: 'visualization', attributes: { visState: '{}' }, references: [] },
3541
];
3642
});
3743

38-
test('should call bulkCreate with each asset', async () => {
44+
test('should call bulkCreate with each asset, filtering out any version if present', async () => {
3945
await importDashboards(savedObjectClient, importedObjects, { overwrite: false, exclude: [] });
4046

4147
expect(savedObjectClient.bulkCreate).toHaveBeenCalledTimes(1);

src/plugins/legacy_export/server/lib/import/import_dashboards.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export async function importDashboards(
3131
// docs are not seen as automatically up-to-date.
3232
const docs = objects
3333
.filter((item) => !exclude.includes(item.type))
34-
.map((doc) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
34+
// filter out any document version, if present
35+
.map(({ version, ...doc }) => ({ ...doc, migrationVersion: doc.migrationVersion || {} }));
3536

3637
const results = await savedObjectsClient.bulkCreate(docs, { overwrite });
3738
return { objects: results.saved_objects };

0 commit comments

Comments
 (0)