abp icon indicating copy to clipboard operation
abp copied to clipboard

ObjectMapper.Map<TSource, TDestination>(source) drops constructor-seeded extra properties (regression since 10.4.1, Mapperly provider)

Open aziz-builds opened this issue 4 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description

Since 10.4.1, the single-parameter IObjectMapper.Map<TSource, TDestination>(source) overload no longer preserves the extension properties that ExtensibleObject's constructor seeds via SetDefaultsForExtraProperties. Extension properties that are registered on the destination but not set on the source now disappear from ExtraProperties entirely, where previously they were present with their default value.

This changes the HTTP wire shape of every extensible DTO. For a user with no value set for a registered extension property:

// 10.1.1
"extraProperties": { "ExternalId": null, "CellphoneNumber": null }
// 10.4.1+
"extraProperties": {}

Any client that reads dto.ExtraProperties["MyProperty"] throws KeyNotFoundException. This is not hypothetical — it broke the Identity user-management grid in our app after upgrading only the Identity service from 10.1.1 to 10.6.0, with the Blazor client still on 10.1.1.

Notably, the two Map overloads now disagree with each other: Map(source, destination) still calls GetExtraProperties(destination) and preserves defaults; Map(source) does not.

Reproduction Steps

The fastest repro is in your own test suite. In framework/test/Volo.Abp.Mapperly.Tests/Mapperly/AbpAutoMapperExtensibleDtoExtensions_Tests.cs, the test MapExtraPropertiesTo_Should_Only_Map_Defined_Properties_By_Default_With_Single_Parameter_Map (added in 61ed99b418) documents the intended behaviour in its comments:

personDto.GetProperty<int>("ChildCount").ShouldBe(0);   //Not defined in the source, but was set to the default value by ExtensibleTestPersonDto constructor
personDto.GetProperty("CityName").ShouldBeNull();       //Ignored, but was set to the default value by ExtensibleTestPersonDto constructor

Tighten those two assertions to check key presence rather than value:

personDto.HasProperty("ChildCount").ShouldBeTrue();   // FAILS on 10.4.1+, passes on 10.1.1
personDto.HasProperty("CityName").ShouldBeTrue();     // FAILS on 10.4.1+, passes on 10.1.1

Both fail. GetProperty<T> returns default(T) for a missing key just as it does for a key holding a default value, so the existing assertions pass either way and cannot detect the regression.

End-to-end repro against a module: register a module extension property on IdentityUser (e.g. via ObjectExtensionManager.Instance.Modules().ConfigureIdentity(...).ConfigureUser(...)), leave it unset on a user, then GET /api/identity/users. On 10.1.1 the key is present with null; on 10.4.1+ extraProperties is {}. Verified locally on 10.6.0 — a freshly constructed IdentityUserDto has all three of our registered keys, and the DTO returned by IIdentityUserAppService.GetListAsync has zero:

REGISTERED on IdentityUserDto: [ExternalId:String, LastSentInvitationDate:Nullable`1, CellphoneNumber:String]
MODULE CONFIG Identity/User:   [ExternalId, CellphoneNumber, LastSentInvitationDate]
FRESH DTO ctor keys:           [ExternalId, LastSentInvitationDate, CellphoneNumber]
DTO admin:                     []
RAW JSON:                      ..."extraProperties":{}

Expected behavior

Extension properties registered on the destination type are present in ExtraProperties with their default value when the source has no value — matching 10.1.1, the Map(source, destination) overload, and the comments in the test above.

Actual behavior

They are absent. The destination's dictionary is replaced with only the keys copied from the source.

Regression?

framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs, commit 61ed99b418 ("Fix ExtraProperties filter bypass in Mapperly single-parameter Map", 2026-05-28, first released in 10.4.1):

 var destination = mapper.Map((TSource)source);
-TryMapExtraProperties(..., destination, GetExtraProperties(destination));
+TryMapExtraProperties(..., destination, new ExtraPropertyDictionary());

(applied to both the mapper and reverse-mapper paths). Downstream in MapExtraProperties:

var result = destinationExtraProperty.IsNullOrEmpty()
    ? new Dictionary<string, object?>()          // now always this branch
    : new Dictionary<string, object?>(destinationExtraProperty);
// ... MapExtraPropertiesTo(source -> result)
ObjectHelper.TrySetProperty(destination, x => x.ExtraProperties, () => new ExtraPropertyDictionary(result));

The result set starts empty and then replaces the destination's dictionary, discarding whatever the constructor seeded.

The original problem the commit addressed is real: Mapperly's generated single-parameter Map can leave destination.ExtraProperties sharing a reference with the source, so GetExtraProperties(destination) returned source data and bypassed the definition/ignore filtering. Passing an empty dictionary fixes that bypass, but also throws away the legitimate constructor defaults, which was not the goal.

Known Workarounds

No response

Version

10.6.0

User Interface

Blazor

Database Provider

EF Core (Default)

Tiered or separate authentication server

Separate Auth Server

Operation System

Linux

Other information

Suggested fix

Seed with the destination type's own defaults instead of an empty dictionary — this cannot leak source data, so the filter fix is preserved:

var seed = new ExtraPropertyDictionary();
seed.SetDefaultsForExtraProperties(typeof(TDestination));   // or equivalent via ObjectExtensionManager
TryMapExtraProperties(..., destination, seed);

Also worth strengthening the tests added in 61ed99b418 to assert with HasProperty rather than GetProperty, so this behaviour is actually pinned.

Impact

Volo.Abp.Mapperly is a framework package, so this affects every extensible DTO in every module, not just Identity. It's especially disruptive for microservice solutions that upgrade services independently: a service on 10.4.1+ silently changes its response shape for clients still on an older ABP, and the failure surfaces as a KeyNotFoundException at render time rather than anything traceable to the upgrade.

Environment

  • ABP Commercial 10.6.0 (regression introduced in 10.4.1; last good 10.1.1)
  • .NET 10, Blazor WebAssembly client + microservice backend
  • Reproduced with Volo.Abp.Identity.Pro (IdentityUserToIdentityUserDtoMapper, which carries [MapExtraProperties])

aziz-builds avatar Jul 28 '26 18:07 aziz-builds

Fixed in https://github.com/abpframework/abp/pull/25891

maliming avatar Jul 30 '26 07:07 maliming