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

Merging object does not allow to set a property value to null #16588

Closed
MikeAlhayek opened this issue Aug 20, 2024 · 1 comment · Fixed by #16589
Closed

Merging object does not allow to set a property value to null #16588

MikeAlhayek opened this issue Aug 20, 2024 · 1 comment · Fixed by #16589
Labels
Milestone

Comments

@MikeAlhayek
Copy link
Member

Describe the bug

I created a custom part:

public class TestContentPart : ContentPart
{
    public int? Minutes { get; set; }
}

Using a driver I have set the Minutes value to a number like 10. Everything works as expected. However, if I want to set it back to null after it was set to 10 the value will not allow setting null. because of this setting

DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,

Orchard Core version

main

To Reproduce

Steps to reproduce the behavior:
Using the following test

  [Fact]
  public void Apply_WhenCalledWithNullProperty_SetThePropertyToNull()
  {
      var contentItem = new ContentItem();

      contentItem.Apply(new TestContentPart()
      {
          Minutes = -15,
      });

      var instance = contentItem.As<TestContentPart>();

      Assert.NotNull(instance);
      Assert.Equal(-15, instance.Minutes);

      contentItem.Apply(new TestContentPart()
      {
          Minutes = null,
      });

      var minutes = (int?)contentItem.Content.TestContentPart.Minutes;

      Assert.Null(minutes);
  }
@MikeAlhayek MikeAlhayek added this to the 2.0 milestone Aug 20, 2024
Copy link
Contributor

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

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

Successfully merging a pull request may close this issue.

1 participant