U4-1460 - Template associated with content is updated when default template of document type changed.

Created by Andy Butland 14 Jan 2013, 07:58:33 Updated by Morten Christensen 31 Jan 2013, 12:24:54

Relates to: U4-1394

I've created a test scenario with a single document type and two allowed templates (A and B). If A is set as the default, a piece of content created using the document type can be created and published with template A. If B is then set as the default template for the document type, re-opening the content for editing sets the template to B, and this is then used when the content is saved and published.

Simply changing the associated template on the content and resaving/republishing saves and retrieves on subsequent edits OK. It's just when the default template on the document type is changed that it gets set to this on the content for subsequent edits.

Have traced through and not quite got my head around what's going on with the caching parts... but it seems that when reloading a piece of content for editing and the information is drawn from the cache it works OK. However when it has to go back to the database - presumably after the cache is invalidated following a document type change - it doesn't retrieve the template associated with the content, and hence reverts to the default for the content type.

Looking in the database, cmsDocument.templateId is null. So it looks like that's not getting saved, although the associated template for the content is saved to the cache.
In ContentFactory.BuildDto the template is not getting populated when reading from the database - there's a note about this as being legacy but unless I've missed something this field will need to be populated and read.

I've attached a small patch for this... seems to resolve the issue reported but of course needs reviewing for any side-effects.

1 Attachments

Download content-template.patch


Morten Christensen 14 Jan 2013, 13:37:20

Hi Andy, Thanks for supplying a patch! It pointed me in the right direction.

I tested a scenario like the one you outlined above and verified that the database is updated correctly when setting the Default template on the Content, as well as only setting and changing it through the DocumentType. As far as I can tell this should now work as expected.

Andy Butland 14 Jan 2013, 14:07:36

No problem Morten, glad it helped. I'll pull down the latest code and check this evening for the scenario I had.

Rusty Swayne 18 Jan 2013, 22:00:02

Hi Morten

I think there is still something wrong with this in nightly build 135.

I had a Text Page document type with an associated view Template (A).

I added a second template (B) for the Text Page and set (B) to the default. Moving back to the content tree all previously published TextPages template (A) now are associated with Template(B). Perhaps this is by design - but I think that it could become a bit problematic if you had lots of content and changed the default template by accident. Perhaps, if this is the case there should be some sort of intermediary confirmation step.

Morten Christensen 19 Jan 2013, 11:29:21

Okay, I'll have to try and reproduce that as I'm pretty sure I have been through this scenario before, and in that case only Content that hadn't previously been saved or published with a template would get updated with the new default template. It could be a regression thing, so not ruling anything out.

Andy Butland 19 Jan 2013, 21:05:34

For what it's worth I checked the latest code after my comment above, and have just done so again - and I can't replicate the original issue as Rusty has described above. Maybe I'm missing something but it looks to me that this has been resolved.

Morten Christensen 21 Jan 2013, 11:11:21

Hi Rusty, I can't reproduce the scenario you are describing. If Text Page has Default Template A, and I change that to Default Template B then previously saved or published Content is still associated with Template A.

If I had a Document that had no allowed templates on the Document Type then that Document would display whatever new default template is added to the DocType, but it won't take effect until that Document is actually published. This is also how it works in v4.

Arild Lindeflaten 31 Jan 2013, 10:37:50

Hi Morten,

This might be related to this: If I do a sort in the content tree, all nodes seems to have changed to default template after sort is done, regardless of what the chosen template where before. Umbraco v6.0.0-RC (Assembly version: 1.0.4769.31461)

Morten Christensen 31 Jan 2013, 12:24:54

@Arild Yes, you are right. I was able to reproduce this issue and it turns out that the template set a on document wasn't loaded properly when not using the default template. This is fixed in changeset f04a97c09ab1 now though.

Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal


Backwards Compatible: True

Fix Submitted: Patch

Affected versions: 6.0.0

Due in version: 6.0.0


Story Points: