LUN-1869: Since we are managing the state of the current site id, it is ...

...important to sync the CMS_TEMPLATES variables as sooner as possible in the request/response cycle, so that even on early middleware chain breaking (caused by some exception), the error page will be displayed correctly with respect to the current site. This fix also ensures that we are able to show the CMS error page even if there is an early exception raised in the middleware chain
At this point cms_tenplates might have the templates from the previous request. You should reset cms_templates before this try except clause:
 <code>
CMS_TEMPLATES = settings.__class__.CMS_TEMPLATES</code>
<code>CMS_TEMPLATES.value = [('dummy','Please create a template first.'),      (settings.CMS_TEMPLATE_INHERITANCE_MAGIC, CMS_TEMPLATE_INHERITANCE_TITLE)]
</code>