Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds support for resolving a property type’s integer DataTypeId from its GUID DataTypeKey when programmatically creating property types.
- Injects
IIdKeyMapinto content-, media-, member-, and template-type repositories and updates constructor signatures accordingly - Replaces
AssignDataTypeFromPropertyEditorwithAssignDataTypeIdFromProvidedKeyOrPropertyEditor, adding logic to map a providedDataTypeKeytoDataTypeIdor fall back to the editor alias - Updates integration test base and repository tests to supply a
Lazy<IIdKeyMap>for new constructor parameters
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/.../TemplateRepositoryTest.cs | Updated ContentTypeRepository instantiation to include IIdKeyMap |
| tests/.../MemberTypeRepositoryTest.cs | Added using and constructor call for IIdKeyMap |
| tests/.../MediaTypeRepositoryTest.cs | Added using and constructor call for IIdKeyMap |
| tests/.../MediaRepositoryTest.cs | Updated instantiation to include IIdKeyMap |
| tests/.../DocumentRepositoryTest.cs | Updated instantiation to include IIdKeyMap |
| tests/.../UmbracoIntegrationTest.cs | Exposed IIdKeyMap in the integration test base |
| src/Umbraco.Infrastructure/.../ContentTypeRepositoryBase.cs | Added _idKeyMap injection and new AssignDataTypeId… logic |
| src/Umbraco.Infrastructure/.../MemberTypeRepository.cs | Injected IIdKeyMap into constructor and base call |
| src/Umbraco.Infrastructure/.../MediaTypeRepository.cs | Injected IIdKeyMap into constructor and base call |
| src/Umbraco.Infrastructure/.../ContentTypeRepository.cs | Injected IIdKeyMap into constructor and base call |
Comments suppressed due to low confidence (5)
src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs:1450
- The new logic for resolving
DataTypeIdfromDataTypeKeyisn't currently covered by existing tests. Consider adding a test that setsDataTypeKeyon a property type and verifies the correctDataTypeIdis applied or that the fallback is used.
if (propertyType.DataTypeKey != Guid.Empty)
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs:268
- This test references
IIdKeyMapbut the namespaceUmbraco.Cms.Core.Servicesisn't imported at the top. Addusing Umbraco.Cms.Core.Services;so the code compiles.
var contentTypeRepository = new ContentTypeRepository(scopeAccessor, AppCaches.Disabled, LoggerFactory.CreateLogger<ContentTypeRepository>(), commonRepository, languageRepository, ShortStringHelper, new Lazy<IIdKeyMap>(() => IdKeyMap));
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs:58
- This test now uses
IIdKeyMapbut the import forUmbraco.Cms.Core.Servicesis missing. Addusing Umbraco.Cms.Core.Services;at the top of this file.
mediaTypeRepository = new MediaTypeRepository(scopeAccessor, appCaches, LoggerFactory.CreateLogger<MediaTypeRepository>(), commonRepository, languageRepository, ShortStringHelper, new Lazy<IIdKeyMap>(() => IdKeyMap));
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs:123
- The constructor call now requires
IIdKeyMap, but this file lacks theUmbraco.Cms.Core.Servicesnamespace import. Please addusing Umbraco.Cms.Core.Services;.
contentTypeRepository = new ContentTypeRepository(scopeAccessor, appCaches, LoggerFactory.CreateLogger<ContentTypeRepository>(), commonRepository, languageRepository, ShortStringHelper, new Lazy<IIdKeyMap>(() => IdKeyMap));
tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs:59
- The integration test base now references
IIdKeyMap; ensureusing Umbraco.Cms.Core.Services;is added so the type is recognized.
protected IIdKeyMap IdKeyMap => Services.GetRequiredService<IIdKeyMap>();
kjac
left a comment
There was a problem hiding this comment.
Looks good 👍 I added a few tests to verify the fix
… data type key (#19720) * Add support for programmatic creation of property types providing the data type key. * Add integration tests --------- Co-authored-by: kjac <kja@umbraco.dk>
* Add support for programmatic creation of property types providing the data type key (#19720) * Add support for programmatic creation of property types providing the data type key. * Add integration tests --------- Co-authored-by: kjac <kja@umbraco.dk> * Don't use Lazy --------- Co-authored-by: Andy Butland <abutland73@gmail.com>
Prerequisites
Resolves: #19715
Description
The linked issue shows that when programmatically creating a property type, only the integer
DataTypeIdis used when determining the data type to use. IfDataTypeKeyis provided, this isn't used and the data type is looked up by property alias. And as there can be more than one of these, you may not end up with the data type you expect.This PR uses the
IIdKeyMapto populate the integer Id from the GUID key if only the latter is provided.Testing
Can be tested with the following surface controller.
Before the update this would create a property type using the "Label (decimal)" data type, even though "Label (jnteger)" was provided. With this update you should see the expected data type used:
Merge and Release
Should be part of 13.10 and merged up to be included in 16.2. When applying for 16, check to see if the use of
Lazyis needed (an initial look suggests it may not be).