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

The same instance of multiple entries in a rich text field are not mapped in a Document #333

Open
peereflits opened this issue May 16, 2024 · 2 comments

Comments

@peereflits
Copy link

Scenario:

Given a rich text field that has one entry "X" and that appears multiple times, once as inline and once as embedded block,
When it is serialized as a Document in the SDK
It should have a Data.Target of the IContent nodes of entry "X"

Actual:
The first IContent node has a Data.Target instance of JObject that can be serialized as 'entry "X"'
The second IContent node has a Data.Target property of null

Expected:
Both IContent nodes hava a Data.Target instance of JObject that can be serialized as 'entry "X"'

Detail information / steps to reproduce

Given Contentfull content type:

{
  "name": "Rich Text example",
  "description": "Demo content model to generate a rich text example.",
  "displayField": "internalTitle",
  "fields": [
    {
      "id": "internalTitle",
      "name": "Internal title",
      "type": "Symbol",
      // other omitted for brevity
    },
    {
      "id": "text",
      "name": "Text",
      "type": "RichText",
      "localized": false,
      "required": true,
      "validations": [
        {
          "enabledMarks": [
            // all, omitted for brevity
          ],
          "message": "Only bold, italic, underline, code, superscript, and subscript marks are allowed"
        },
        {
          "enabledNodeTypes": [
            // all other node types enabled, omitted for brevity
            "embedded-entry-block",
            "entry-hyperlink",
            "embedded-entry-inline"
          ],
          "message": "a custom error message"
        },
        {
          "nodes": {}
        }
      ],
      "disabled": false,
      "omitted": false
    }
  ],
  "sys": {
	// omitted for brevity
    },
    "id": "richTextDemo",
    "type": "ContentType",
	// Other properties omitted for brevity

    "urn": "crn:contentful:::content:spaces/{spaceId}/environments/develop/content_types/richTextDemo"
  }
}

This type can be serialized as dotnet type:

internal record RichTextDemo
{
    public required SystemProperties Sys { get; set; }
    public string? InternalTitle { get; set; }
    public required Document Text { get; set; }
}

In Contentful prepare an instance of richTextTyDemo and add an "embedded-entry-inline" entry that references an other content type instance and add an "embedded-entry-block" that references the same content type instance.

When execute a query with a valid entryId like this:

private async Task<RichTextDemo> GetDemoDocument(string entryId)
{
	IContentfulClient client = CreateClient();

	var builder = new QueryBuilder<RichTextDemo>()
		.ContentTypeIs("richTextDemo")
		.FieldEquals(f => f.Sys.Id, entryId)
		.LocaleIs("en")
		.Limit(1)
		.Include(10);

	var result = (await client.GetEntries(builder)).Single();
	return result;
}

The result of this query should be:

  1. result is not null and of type RichTextDemo => true
  2. result has a property Text of type Document and is not null => true
  3. The Text has two IContent nodes with a Data.Target propoerty that can be serialized to that referenced instance => false

The first IContent node has a serializable Data.Target.

The second IContent node has a Data.Target that is null.

I suspect that the error is in the ContentfulClient between Line 233 and Line 271.

@Roblinde
Copy link
Collaborator

hi @peereflits

Have you had a look at this blog post I wrote a while back? https://robertlinde.se/posts/why-is-my-item-null-contentful-net/

Not sure if this is the root cause in this particular scenario, but setting a content type resolver and also potentially ResolveEntriesSelectively might resolve the issue.

@peereflits
Copy link
Author

Hi @Roblinde ,
Thanks for the feedback. I'll look into it.

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

No branches or pull requests

2 participants