# Buggy code
def gen_tasks(self):
    """Render the tag pages and feeds."""
    self.site.scan_posts()
    yield self.group_task()

    for lang in self.site.config["TRANSLATIONS"]:
        # To support that tag and category classifications share the same overview,
        # we explicitly detect this case:
        ignore_plugins_for_overview = set()
        if (
            "tag" in self.site.taxonomy_plugins
            and "category" in self.site.taxonomy_plugins
            and self.site.link("tag_index", None, lang)
            == self.site.link("category_index", None, lang)
        ):
            # Block both plugins from creating overviews
            ignore_plugins_for_overview.add(self.site.taxonomy_plugins["tag"])
            ignore_plugins_for_overview.add(self.site.taxonomy_plugins["category"])
        for taxonomy in self.site.taxonomy_plugins.values():
            if not taxonomy.is_enabled(lang):
                continue
            # Generate list of classifications (i.e. classification overview)
            if taxonomy not in ignore_plugins_for_overview:
                if taxonomy.template_for_classification_overview is not None:
                    for task in self._generate_classification_overview(taxonomy, lang):
                        yield task

            # Generate classification lists
            classifications = {}
            for tlang, posts_per_classification in self.site.posts_per_classification[
                taxonomy.classification_name
            ].items():
                if (
                    lang != tlang
                    and not taxonomy.also_create_classifications_from_other_languages
                ):
                    continue
                classifications.update(posts_per_classification)

            # Process classifications
            for classification, posts in classifications.items():
                for task in self._generate_classification_page(
                    taxonomy, classification, posts, lang
                ):
                    yield task
        # In case we are ignoring plugins for overview, we must have a collision for
        # tags and categories. Handle this special case with extra code.
        if ignore_plugins_for_overview:
            for task in self._generate_tag_and_category_overview(
                self.site.taxonomy_plugins["tag"],
                self.site.taxonomy_plugins["category"],
                lang,
            ):
                yield task


# Traceback (KeyError)
########################################
TaskError - taskid:render_galleries:output/galleries/index.html
PythonAction Error
Traceback (most recent call last):
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/kwpolska/git/nikola/nikola/plugins/task/galleries.py", line 466, in render_gallery_index
self.site.render_template(template_name, output_name, context)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 607, in render_template
template_name, None, local_context)
File "/home/kwpolska/git/nikola/nikola/plugins/template/mako.py", line 88, in render_template
data = template.render_unicode(**context)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/kwpolska/virtualenvs/nikola-py2/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base.tmpl.py", line 91, in render_body
__M_writer(unicode(base.meta_translations()))
File "/home/kwpolska/Desktop/nikola-translated-path/cache/.mako.tmp/base_helper.tmpl.py", line 274, in render_meta_translations
__M_writer(unicode(_link(permalink, None, langname)))
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 765, in link
return self.path(*args, is_link=True)
File "/home/kwpolska/git/nikola/scripts/../nikola/nikola.py", line 729, in path
path = self.path_handlers[kind](name, lang)
KeyError: u'/galleries/galleries/index.html'

# Fixed code
def gen_tasks(self):
    """Render the tag pages and feeds."""
    self.site.scan_posts()
    yield self.group_task()

    # Cache classification sets per language for taxonomies where
    # add_other_languages_variable is True.
    classification_set_per_lang = {}
    for taxonomy in self.site.taxonomy_plugins.values():
        if taxonomy.add_other_languages_variable:
            lookup = self.site.posts_per_classification[taxonomy.classification_name]
            cspl = {lang: set(lookup[lang].keys()) for lang in lookup}
            classification_set_per_lang[taxonomy.classification_name] = cspl

    # Collect post lists for classification pages and determine whether
    # they should be generated.
    post_lists_per_lang = {}
    for taxonomy in self.site.taxonomy_plugins.values():
        plpl = {}
        for lang in self.site.config["TRANSLATIONS"]:
            classifications = {}
            for tlang, posts_per_classification in self.site.posts_per_classification[
                taxonomy.classification_name
            ].items():
                if (
                    lang != tlang
                    and not taxonomy.also_create_classifications_from_other_languages
                ):
                    continue
                classifications.update(posts_per_classification)
            result = {}
            for classification, posts in classifications.items():
                # Filter list
                filtered_posts = self._filter_list(posts, lang)
                if len(filtered_posts) == 0 and taxonomy.omit_empty_classifications:
                    generate_list = False
                    generate_rss = False
                else:
                    # Should we create this list?
                    generate_list = taxonomy.should_generate_classification_page(
                        classification, filtered_posts, lang
                    )
                    generate_rss = taxonomy.should_generate_rss_for_classification_page(
                        classification, filtered_posts, lang
                    )
                result[classification] = (filtered_posts, generate_list, generate_rss)
            plpl[lang] = result
        post_lists_per_lang[taxonomy.classification_name] = plpl

    # Now generate pages
    for lang in self.site.config["TRANSLATIONS"]:
        # To support that tag and category classifications share the same overview,
        # we explicitly detect this case:
        ignore_plugins_for_overview = set()
        if (
            "tag" in self.site.taxonomy_plugins
            and "category" in self.site.taxonomy_plugins
            and self.site.link("tag_index", None, lang)
            == self.site.link("category_index", None, lang)
        ):
            # Block both plugins from creating overviews
            ignore_plugins_for_overview.add(self.site.taxonomy_plugins["tag"])
            ignore_plugins_for_overview.add(self.site.taxonomy_plugins["category"])
        for taxonomy in self.site.taxonomy_plugins.values():
            if not taxonomy.is_enabled(lang):
                continue
            # Generate list of classifications (i.e. classification overview)
            if taxonomy not in ignore_plugins_for_overview:
                if taxonomy.template_for_classification_overview is not None:
                    for task in self._generate_classification_overview(taxonomy, lang):
                        yield task

            # Process classifications
            for classification, (
                filtered_posts,
                generate_list,
                generate_rss,
            ) in post_lists_per_lang[taxonomy.classification_name][lang].items():
                for task in self._generate_classification_page(
                    taxonomy,
                    classification,
                    filtered_posts,
                    generate_list,
                    generate_rss,
                    lang,
                    post_lists_per_lang[taxonomy.classification_name],
                    classification_set_per_lang.get(taxonomy.classification_name),
                ):
                    yield task
        # In case we are ignoring plugins for overview, we must have a collision for
        # tags and categories. Handle this special case with extra code.
        if ignore_plugins_for_overview:
            for task in self._generate_tag_and_category_overview(
                self.site.taxonomy_plugins["tag"],
                self.site.taxonomy_plugins["category"],
                lang,
            ):
                yield task