-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Getting content element by name and type can fail even if valid #15973
Comments
Why are you calling shouldn’t you use this instead |
I am trying to read some properties from basically all parts in content item but in graphql where those parts are already loaded with dynamic providers(e.g. this). It's kind of shady and will understand if it's not a bug for you, but on the other side it's a public extension method that can cause unwanted effect |
I think this is currently by design, but quite unfortunate. The first usage of |
Maybe add a new method that does not check the cache. At least whom ever consumes it, will hopefully have a good reason to use it. |
I still didn't understand what was wrong with |
As<> in the end uses this Get and won't work if you ever read content with different type |
To make it more clear, the following test will throw. Not sure if we want to allow this: [Fact]
public void ShouldDeserializeMoreSpecificTypes()
{
var contentItem = new ContentItem();
var myPart = new MyPart { Text = "test" };
contentItem.Weld(myPart);
var json = JConvert.SerializeObject(contentItem);
var contentItem2 = JConvert.DeserializeObject<ContentItem>(json);
// act
var contentPart = contentItem2.Get<ContentPart>(nameof(MyPart));
// This will throw
var actualMyPart = contentItem2.Get<MyPart>(nameof(MyPart));
// assert
Assert.NotNull(actualMyPart);
} |
…name-and-type-can-fail-even-if-valid
Describe the bug
When you try to get some content part lets say BlogPart from content item you can use extension method ContentExtensions.Get . Bug occurs when there are multiple valid casts of content part.
To Reproduce
Steps to reproduce the behavior:
contentItem.Get<ContentPart>("BlogPart")
contentItem.Get<BlogPart>("BlogPart")
Expected behavior
casts are valid should recast object
The text was updated successfully, but these errors were encountered: