-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Source object is frozen when mapped #467
Comments
I think the issue is caused by the mapper proxy: // packages/core/src/lib/core.ts - Mapper.map
if (sourceObject == null)
return sourceObject as TDestination;
const mapping = getMapping(
receiver,
sourceIdentifier,
destinationIdentifier
);
sourceObject = strategy.preMap(
Object.freeze(sourceObject),
mapping
);
const destination = mapReturn(
mapping,
sourceObject,
options || {}
);
return strategy.postMap(
Object.freeze(sourceObject),
// seal destination so that consumers cannot add properties to it
// or change the property descriptors. but they can still modify it
// the ideal behavior is seal but the consumers might need to add/modify the object after map finishes
destination,
mapping
); It looks like the source frozen to prevent side effects by pre-/postMap, but according to the documentation of
I think the source should be copied before freezing or freezing the source should be omitted completely leaving it to the user to make sure that the pre and post methods are side effect free. |
Prevent freezing of the given source object as side effect of map(Array)/mutate(Array). Create shallow copy of source before freezing it and using the frozen copy for the remaining mapping process. ISSUES CLOSED: nartc#467
* fix(core): fix freezing of source object after mapping Prevent freezing of the given source object as side effect of map(Array)/mutate(Array). Create shallow copy of source before freezing it and using the frozen copy for the remaining mapping process. ISSUES CLOSED: #467 * cleanup(core): remove unused imports in test file * fix(core): remove freezing source object during mapping ISSUES CLOSED: #467
Is there an existing issue for this?
Describe the issue
The source object is frozen after it has been mapped, resulting in errors like
TypeError: Cannot assign to read only property 'name' of object '#<Foo>'
when trying to change the source afterwards. Probably related to #464.Models/DTOs/VMs
No response
Mapping configuration
No response
Steps to reproduce
Output
Expected behavior
The source object should be mutable after it was mapped.
Screenshots
No response
Minimum reproduction code
No response
Package
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/mikro
@automapper/sequelize
Other package and its version
No response
AutoMapper version
8.3.3
Additional context
No response
The text was updated successfully, but these errors were encountered: