Skip to content

Commit f4ef754

Browse files
mgabeler-lee-6rsachrinza
authored andcommitted
fix(repository): use a shallow clone for applying polymorphism to options
The `options` object will often have a `transaction`, which contains database connection resources that must not be cloned. Fixes #10194, introduced by #8026 Signed-off-by: Matthew Gabeler-Lee <mgabeler-lee@6river.com>
1 parent f664a76 commit f4ef754

4 files changed

Lines changed: 7 additions & 11 deletions

File tree

packages/repository/src/relations/belongs-to/belongs-to.repository.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
import {Getter} from '@loopback/core';
7-
import {cloneDeep} from 'lodash';
87
import {EntityNotFoundError, TypeResolver} from '../../';
98
import {DataObject, Options} from '../../common-types';
109
import {Entity} from '../../model';
@@ -101,7 +100,7 @@ export class DefaultBelongsToRepository<
101100
result = result.concat(
102101
await targetRepository.find(
103102
constrainFilter(undefined, this.constraint),
104-
Object.assign(cloneDeep(options ?? {}), {polymorphicType: key}),
103+
{...options, polymorphicType: key},
105104
),
106105
);
107106
if (result.length >= 1) {

packages/repository/src/relations/has-many/has-many-through.repository.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {cloneDeep} from 'lodash';
76
import {
87
constrainDataObject,
98
constrainFilter,
@@ -304,10 +303,10 @@ export class DefaultHasManyThroughRepository<
304303
throughCategorized[key],
305304
);
306305
allTargets = allTargets.concat(
307-
await targetRepository.find(
308-
constrainFilter(filter, targetConstraint),
309-
Object.assign(cloneDeep(options ?? {}), {polymorphicType: key}),
310-
),
306+
await targetRepository.find(constrainFilter(filter, targetConstraint), {
307+
...options,
308+
polymorphicType: key,
309+
}),
311310
);
312311
}
313312

packages/repository/src/relations/has-one/has-one.inclusion-resolver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
import {Filter, InclusionFilter} from '@loopback/filter';
7-
import {cloneDeep} from 'lodash';
87
import {includeFieldIfNot, InvalidPolymorphismError} from '../../';
98
import {AnyObject, Options} from '../../common-types';
109
import {Entity} from '../../model';
@@ -113,7 +112,7 @@ export function createHasOneInclusionResolver<
113112
targetKey,
114113
sourceIdsCategorized[k],
115114
scope,
116-
Object.assign(cloneDeep(options ?? {}), {polymorphicType: k}),
115+
{...options, polymorphicType: k},
117116
);
118117
targetCategorized[k] = flattenTargetsOfOneToOneRelation(
119118
sourceIdsCategorized[k],

packages/repository/src/relations/has-one/has-one.repository.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import {Getter} from '@loopback/core';
77
import {Filter, Where} from '@loopback/filter';
8-
import {cloneDeep} from 'lodash';
98
import {TypeResolver} from '../../';
109
import {Count, DataObject, Options} from '../../common-types';
1110
import {EntityNotFoundError, InvalidPolymorphismError} from '../../errors';
@@ -182,7 +181,7 @@ export class DefaultHasOneRepository<
182181
const targetRepository = await this.getTargetRepositoryDict[key]();
183182
const found = await targetRepository.find(
184183
Object.assign({limit: 1}, constrainFilter(filter, this.constraint)),
185-
Object.assign(cloneDeep(options ?? {}), {polymorphicType: key}),
184+
{...options, polymorphicType: key},
186185
);
187186
if (found.length >= 1) {
188187
return found[0];

0 commit comments

Comments
 (0)