umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.4k stars 2.66k forks source link

PublishedContent Null After v13.3 Upgrade #16187

Open joshanangelofgrace opened 4 months ago

joshanangelofgrace commented 4 months ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.3.0

Bug summary

We are upgrading a site from v12 to v13 and noticed one of our custom routes no longer works. I did some digging and found that for this route the PublishedContent on the request is null in v13 when it was not null in v12

v12: image

v13: image

Specifics

Note for your info this is the code of the controller:

on v12 the 'in' route/method was being correctly hit

in v13 this is not even hit and a 404 comes up on the site

[Route("contact")]
public class ContactController : RenderController
 {
     private readonly ILogger<RenderController> logger;
     private readonly CountryRepository countryRepository;
     private readonly ContactRepository contactRepository;
     private readonly IScopeProvider provider;
     private readonly IPersonalisationService personalisationService;
     private readonly IVariationContextAccessor variationContextAccessor;
     private readonly ServiceContext serviceContext;

     public ContactController(CountryRepository countryRepository, ContactRepository contactRepository,
                              IScopeProvider provider, IPersonalisationService personalisationService,
                              ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine,
                              IUmbracoContextAccessor umbracoContextAccessor,
                              IVariationContextAccessor variationContextAccessor, ServiceContext serviceContext)
         : base(logger, compositeViewEngine, umbracoContextAccessor)
     {
         this.variationContextAccessor = variationContextAccessor;
         this.serviceContext = serviceContext;
         this.countryRepository = countryRepository;
         this.contactRepository = contactRepository;
         this.provider = provider;
         this.personalisationService = personalisationService;
         this.logger = logger;
     }

     [Route("in/{countryKey}")]
     public IActionResult In(string countryKey)
     {
         logger.LogDebug("Retrieving information for country {countryKey}", countryKey);

         using (provider.CreateScope(autoComplete: true))
         {
             personalisationService.EnsureSessionProps(HttpContext);
             // ensure country URL uses ISO codes, and is lower case.
             var country = countryRepository.Find(countryKey);
             var sourceCountry = country;
             if (country == null)
             {
                 return new RedirectResult($"/contact/in/");
             }
             else if (countryKey != country.IsoKey.ToLower())
             {
                 return new RedirectResult($"/contact/in/{country.IsoKey.ToLower()}/");
             }

             var distributors = contactRepository.Get(ContactType.Distributor, sourceCountry).ToList();
             var reps = contactRepository.Get(ContactType.SalesRep, sourceCountry).ToList();

             if (distributors.Count + reps.Count == 0)
             {
                 // attempt to redirect
                 sourceCountry = countryRepository.FindRedirected(country);
                 distributors = contactRepository.Get(ContactType.Distributor, sourceCountry).ToList();
                 reps = contactRepository.Get(ContactType.SalesRep, sourceCountry).ToList();
             }
             if (distributors.Count + reps.Count == 0)
             {
                 // ignore redirect, expand to region
                 sourceCountry = country;
                 distributors = contactRepository.GetFromRegion(ContactType.Distributor, country.RegionName).ToList();
                 reps = contactRepository.GetFromRegion(ContactType.SalesRep, country.RegionName).ToList();
             }

             var model = new ContactPageViewModel(CurrentPage, new PublishedValueFallback(serviceContext, variationContextAccessor))
             {
                 IsCurrentCountry = personalisationService.UserSession.Country?.Code == country.IsoKey,
                 Country = country,
                 RedirectedTo = sourceCountry,
                 Distributors = distributors,
                 SalesReps = reps
             };

             logger.LogDebug("Country Information: {@Model}", model);

             return PartialView("CountryView", model);
         }
     }
 }

Steps to reproduce

Set up a custom route - note that this route has no content behind it.

See if the route is being hit correctly

Expected result / actual result

No response

github-actions[bot] commented 4 months ago

Hi there @joshanangelofgrace!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

Migaroez commented 1 month ago

Hey @joshanangelofgrace thank you for taking the time to supply this detailed report. A fjew questions:

Disclaimer: I updated your submission by adding the csharp identifier to the opening codebraces ```csharp which results in nicer formating and placed the closing code braces on their own line so the rest of your response is properly formatted