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

Sitemap import/export does not work #16434

Closed
sarahelsaig opened this issue Jul 12, 2024 · 1 comment · Fixed by #16436
Closed

Sitemap import/export does not work #16434

sarahelsaig opened this issue Jul 12, 2024 · 1 comment · Fixed by #16436
Labels
Milestone

Comments

@sarahelsaig
Copy link
Contributor

Describe the bug

I've found two STJ problems with sitemap import & export. Both are related to polymorphic deserialization so it's the same bug.

  1. If you try to export a new site map, the sitemap source will only contain the Id property, all other details are lost. It seems like the object is serialized as just SitemapSource instead of the derived type ContentTypesSitemapSource. See in the repro below.
  2. When the site tries to parse a recipe from OC 1.8 containing the "Sitemaps" step, it throws the following, even before the recipe is executed. You can find the example error and the JSON that causes it below:

Orchard Core version

The latest main branch and 2.0.0-preview-18268 Cloudsmith package.

To Reproduce

Steps to reproduce the export error:

  1. Create a site (example using Blog recipe).
  2. Enable the "Sitemaps" feature.
  3. Go to Admin > Configuration > SEO > Sitemaps.
  4. Add a sitemap and a "Sitemap Content Types" source (I unchecked "Index All Content Types" and picked just Page and BlogPost).
  5. Go to Admin > Configuration > Import/Export > Deployment Plans.
  6. Create a deployment plan and add the "All Sitemaps" step.
  7. Execute the deployment and open the resulting JSON.
  8. Observe, that the SitemapSources is missing all details (expected something similar to the JSON in the logs section instead):
    {
      "name": "",
      "displayName": "",
      "description": "",
      "author": "",
      "website": "",
      "version": "",
      "issetuprecipe": false,
      "categories": [],
      "tags": [],
      "steps": [
        {
          "name": "Sitemaps",
          "data": [
            {
              "SitemapId": "4g45p23q02vgpvm40vznd49t56",
              "Name": "Sitemap",
              "Enabled": true,
              "Path": "sitemap.xml",
              "SitemapSources": [
                {
                  "Id": "4nqc3qwb76te707aq12qapkh4y"
                }
              ],
              "Identifier": "4vtsxzdvm15qmxv5fbttrhh054"
            }
          ]
        }
      ]
    }
  9. Go to Admin > Configuration > Import/Export > JSON Import
  10. Paste the freshly exported site map.
  11. Observe the error message Unexpected error occurred while executing the 'Sitemaps' step.
  12. Observe the error in the log: Unable to import a recipe from JSON input. OrchardCore.Recipes.Models.RecipeExecutionException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'OrchardCore.Sitemaps.Models.SitemapType'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.

Expected behavior

If possible, import from OC 1.x recipe should work. If that's not feasible, a note should be added into the release notes breaking changes section.
Export should include all

Logs and screenshots

If applicable, add log files, browser console logs, and screenshots (or screen recording videos) to help explain your problem.

This is example sitemap recipe from OC 1.8 that used to work:

{
  "name": "Redacted.Sitemaps",
  "displayName": "Redacted - Content - Sitemaps Definition",
  "description": "Sitemaps for Redacted site.",
  "author": "Lombiq",
  "version": "1.0",
  "categories": [ "content" ],
  "tags": [ "sitemaps" ],
  "steps": [
    {
      "name": "Sitemaps",
      "data": [
        {
          "$type": "OrchardCore.Sitemaps.Models.Sitemap, OrchardCore.Sitemaps.Abstractions",
          "SitemapId": "4vbscpv3kgcnz192hnwwggh0d7",
          "Name": "Sitemap",
          "Enabled": true,
          "Path": "sitemap.xml",
          "SitemapSources": [
            {
              "$type": "OrchardCore.Sitemaps.Models.ContentTypesSitemapSource, OrchardCore.Sitemaps.Abstractions",
              "IndexAll": false,
              "LimitItems": false,
              "ChangeFrequency": 0,
              "Priority": 5,
              "ContentTypes": [
                {
                  "ContentTypeName": "BlogPost",
                  "ChangeFrequency": 0,
                  "Priority": 0
                },
                {
                  "ContentTypeName": "Page",
                  "ChangeFrequency": 0,
                  "Priority": 0
                }
              ],
              "Id": "45naf8my0kdgd3tsf5vwtf94xq"
            }
          ],
          "Identifier": "4mg5ntbxrs9c57w8nybtgvyvcf"
        }
      ]
    }
  ]
}

This is the error log that shows up now:

2024-07-12 16:21:28.3105|test|00-6c4d175cf6fcafcbc633522a4d8c5e63-82c762aa10e7f9c7-00||OrchardCore.Setup.Services.SetupService|ERROR|Unable to import a recipe during setup. OrchardCore.Recipes.Models.RecipeExecutionException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'OrchardCore.Sitemaps.Models.SitemapType'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
 ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'OrchardCore.Sitemaps.Models.SitemapType'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
 ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'OrchardCore.Sitemaps.Models.SitemapType'.
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeNoConstructor(Type type, Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromNode[TValue](JsonNode node, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](JsonNode node, JsonSerializerOptions options)
   at System.Text.Json.Nodes.JNode.ToObject[T](JsonNode jsonNode, JsonSerializerOptions options)
   at OrchardCore.Sitemaps.Recipes.SitemapsStep.ExecuteAsync(RecipeExecutionContext context)
   at OrchardCore.Recipes.Services.RecipeExecutor.<>c__DisplayClass8_0.<<ExecuteStepAsync>b__0>d.MoveNext()
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.

2 participants