-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Saved objects client - bulkUpdate] Passing the correct namespace to migrateInputDocument #222313
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
Changes from all commits
791a5ee
c122b83
15ebfd8
ddbc57b
d18b2aa
e43846a
b587d1d
f0d27f3
95c38f3
f902c06
3ba40ab
70aa25f
a248161
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,17 +150,11 @@ export const performBulkUpdate = async <T>( | |
| }; | ||
| } | ||
|
|
||
| // `objectNamespace` is a namespace string, while `namespace` is a namespace ID. | ||
| // The object namespace string, if defined, will supersede the operation's namespace ID. | ||
| const namespaceString = SavedObjectsUtils.namespaceIdToString(namespace); | ||
|
|
||
| const getNamespaceId = (objectNamespace?: string) => | ||
| objectNamespace !== undefined | ||
| ? SavedObjectsUtils.namespaceStringToId(objectNamespace) | ||
| : namespace; | ||
|
|
||
| const getNamespaceString = (objectNamespace?: string) => objectNamespace ?? namespaceString; | ||
|
|
||
| const bulkGetDocs = validObjects.map(({ value: { type, id, objectNamespace } }) => ({ | ||
| _id: serializer.generateRawId(getNamespaceId(objectNamespace), type, id), | ||
| _index: commonHelper.getIndexForType(type), | ||
|
|
@@ -235,7 +229,6 @@ export const performBulkUpdate = async <T>( | |
| mergeAttributes, | ||
| } = expectedBulkGetResult.value; | ||
|
|
||
| let namespaces: string[] | undefined; | ||
| const versionProperties = getExpectedVersionProperties(version); | ||
| const indexFound = bulkGetResponse?.statusCode !== 404; | ||
| const actualResult = indexFound ? bulkGetResponse?.body.docs[esRequestIndex] : undefined; | ||
|
|
@@ -258,15 +251,18 @@ export const performBulkUpdate = async <T>( | |
| }); | ||
| } | ||
|
|
||
| let savedObjectNamespace: string | undefined; | ||
| let savedObjectNamespaces: string[] | undefined; | ||
|
|
||
| if (isMultiNS) { | ||
| // @ts-expect-error MultiGetHit is incorrectly missing _id, _source | ||
| namespaces = actualResult!._source.namespaces ?? [ | ||
| savedObjectNamespaces = actualResult!._source.namespaces ?? [ | ||
| // @ts-expect-error MultiGetHit is incorrectly missing _id, _source | ||
| SavedObjectsUtils.namespaceIdToString(actualResult!._source.namespace), | ||
| ]; | ||
| } else if (registry.isSingleNamespace(type)) { | ||
| // if `objectNamespace` is undefined, fall back to `options.namespace` | ||
| namespaces = [getNamespaceString(objectNamespace)]; | ||
| savedObjectNamespace = objectNamespace ?? namespace; | ||
| } | ||
|
|
||
| const document = getSavedObjectFromSource<T>( | ||
|
|
@@ -310,8 +306,8 @@ export const performBulkUpdate = async <T>( | |
| ...migrated!, | ||
| id, | ||
| type, | ||
| namespace, | ||
| namespaces, | ||
| ...(savedObjectNamespace && { namespace: savedObjectNamespace }), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't comment on the right place, but in line 297 should we fallback to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually doesn't matter if we pass a namespace ID or a namespace string to the encryption extension - it will always get "normalized" and used appropriately.
Disregard...I forgot that we do not use namespace in the descriptor for multi-namespace ESOs. |
||
| ...(savedObjectNamespaces && { namespaces: savedObjectNamespaces }), | ||
| attributes: updatedAttributes, | ||
| updated_at: time, | ||
| updated_by: updatedBy, | ||
|
|
@@ -321,6 +317,9 @@ export const performBulkUpdate = async <T>( | |
| migratedUpdatedSavedObjectDoc as SavedObjectSanitizedDoc | ||
| ); | ||
|
|
||
| const namespaces = | ||
| savedObjectNamespaces ?? (savedObjectNamespace ? [savedObjectNamespace] : []); | ||
|
|
||
| const expectedResult = { | ||
| type, | ||
| id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.