Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Jul 29, 2022 @ 10:57
    Jesper Ordrup
    0

    Umbraco content api returns incorrect blocklist data when calling from umbracoapicontroller / umbracosurfacecontroller

    When retrieving content via api we get the wrong data in blocklists. Only on some pages. Some pages consistently returns the right data and some consistently returns the wrong data.

    If we look at the page rendered in an Umbraco view - content is rendered correct.

    This works in the view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Page>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    }
    
    @Html.GetBlockListHtml(Model, "blocks")
    

    Here are some examples that doesnt work

    Example 1 : The umbracoapicontroller

    In the controller we get data like this:

    public IHttpActionResult Get(int id, int levels = 1)
            {
    
               IPublishedContent content = UmbracoContext.Content.GetById(id);
    

    Example 2 : The umbracoapicontroller and umbracohelper

    In the controller we get data like this:

    public IHttpActionResult Get(int id, int levels = 1)
            {
    
               IPublishedContent content = Umbraco.Content(id);
    

    *Example 3: The Umbraco Surface controller *

      [HttpGet]
        public JsonResult Get(int id = 1090, int levels = 1)
        {
    
            var content = UmbracoContext.Content.GetById(id);
    

    Same difference in all 3 examples. If I debug and inspect content I can find examples where one or more of the blocks in the block list is wrong.

    I can fix the problem

    A few things tried:

    • If the editor, in Umbraco updates the block - the problem remains the same.

    • If the editor, in Umbraco sorts / moves the block - the problem remains the same.

    • If the editor copies the block and insert a new copy - the problem is fixed

    Some facts

    Problem was first spotted on a solution running on an Umbraco.sdf. We've tested migrating to sqlexpress. Problem still there.

    Discovered in Umb 8.14.1. Upgraded to latest 8.18.4. Problem still there.

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Aug 02, 2022 @ 18:36
    Jesper Ordrup
    0

    Seen this b4? Any hints?

    😀

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Sep 26, 2022 @ 12:05
    Jesper Ordrup
    0

    Update:

    I have traced the problem into page created with content from "Content Templates".

    Didnt find the reason behind.

  • Anders Bjerner 487 posts 2990 karma points MVP 8x admin c-trib
    Sep 26, 2022 @ 13:09
    Anders Bjerner
    100

    IIRC the issue happens when blocks on two different pages share the same GUID key.

    If this can be reproduced by creating a new page from a content template, I'd say this is a bug in Umbraco.

    We had the issue with one of our sites. I don't know whether this was caused by content templates, or some other form of copying content. I think I tested a few scenarios where I couldn't reproduce duplicate keys.

    Anyways, I ended up writing some quick code to run through the affected pages and replace the GUID keys with randomly generated GUIDs (I don't think I have the code anymore).

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Sep 26, 2022 @ 13:16
    Jesper Ordrup
    0

    Thanks for confirming my finding, Anders ( IIRC I was close to loosing my mind at that time ).

    ps. IIRC - had to look it up but I'll prefix everything with that from now on.

Please Sign in or register to post replies

Write your reply to:

Draft