Skip to content
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

ModelsBuilder GetModelPropertyType fails when the "itemType" is "Element" #14694

Closed
hfloyd opened this issue Aug 17, 2023 · 6 comments
Closed

Comments

@hfloyd
Copy link
Contributor

hfloyd commented Aug 17, 2023

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

10.6.1

Bug summary

I have a Composition Document type, lets call it "CompMyData". It has some properties, and is on some Document types used for nodes.

I have some code like this, to get the exact alias of a composition property:
var aliasMyProp = CompMyData.GetModelPropertyType(_publishedSnapshotAccessor, x => x.MyProperty).Alias;

but it throws an error when it runs:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'itemType')
   at Umbraco.Cms.Infrastructure.ModelsBuilder.PublishedModelUtility.GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor, PublishedItemType itemType, String alias)
   at MyNamespace.Models.CompMyData.GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) ...

I am using Limbo ModelsBuilder for the model generation, and the code in question looks like this:

 public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<CompMyData, TValue>> selector)
     => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);

Specifics

The error occurs in Umbraco.Cms.Infrastructure.ModelsBuilder.PublishedModelUtility.GetModelContentType()

image

Steps to reproduce

Attempt to use GetModelPropertyType() on a Model for a Composition.

Expected result / actual result

I just wanted to get the property alias.

Resolution?

Should "Element" be added as an acceptable itemType?

@github-actions
Copy link

Hi there @hfloyd!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@Zeegaan
Copy link
Member

Zeegaan commented Aug 21, 2023

Hmm I cannot reproduce this sadly 😕

This is me on 10.6.1:
image

@Zeegaan Zeegaan added the state/needs-reproduction Check if this can be reproduced in the latest released version label Aug 21, 2023
@hfloyd
Copy link
Contributor Author

hfloyd commented Sep 5, 2023

Hi @Zeegaan , Thanks for looking into this. Do you see what the "itemType" is returning when you step into that method? When I run it, "itemType" = "Element" - which isn't included in the switch statement...

@Zeegaan
Copy link
Member

Zeegaan commented Sep 7, 2023

Yea apparently I just forgot to re-build my models after switching to the Limbo modelsbuilder 🙈
We had a talk and agreed this is a bug, and have made a PR implementing your suggestion @hfloyd 🙌
Fixed in #14776

@Zeegaan Zeegaan closed this as completed Sep 7, 2023
@Zeegaan Zeegaan added release/12.3.0 release/10.9.0 release/10.8.0 and removed state/needs-reproduction Check if this can be reproduced in the latest released version release/10.9.0 labels Sep 7, 2023
@abjerner
Copy link
Contributor

abjerner commented Sep 7, 2023

Awesome 👍

I hadn't even spotted this. I tried to do the same as Umbraco's models builder for my package, so not sure if something has changed in Umbraco since then, or I just ended up doing this part slightly different.

@hfloyd
Copy link
Contributor Author

hfloyd commented Sep 7, 2023

Great news, @Zeegaan ! Thanks for checking again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants