Every extension kind covered so far in this series list, tab, detail, filter, nav works the same way underneath: something in Horilla calls a resolution point (as_view(), get_filterset_class(), get_form_class()) that decides which class actually runs, and the extension framework swaps in a freshly composed subclass at that moment. It’s a clean pattern, but it only works when such a resolution point exists.

Some targets don’t have one. A plain mixin class like HorillaListFilterFieldsMixin is never instantiated or dispatched on its own; it’s only ever combined into other classes through ordinary multiple inheritance, at class-definition time, long before any request comes in. A bare module-level function like get_export_cell_value is just called directly by name wherever it’s imported. Neither has a moment where Horilla CRM “picks a class” that could be intercepted and swapped.

_inherit_mixin exists to close exactly that gap.

What Problem Does This Actually Solve?

Horilla’s own documentation lays out the comparison plainly:

MechanismRequires
_inherit_viewTarget dispatched via as_view()
_inherit_formTarget resolved via get_form_class()
_inherit_filterTarget resolved via get_filterset_class()
_inherit_list / _inherit_kanban / _inherit_card / _inherit_detailTarget dispatched via its own as_view()
_inherit_formatterTarget resolved via get_datetime_formatter()
A bare mixin or bare functionNothing calls any of the above on it — there is no resolution point

The documentation’s own framing of the fix: “_inherit_mixin closes this last gap by patching the target directly, once, at startup the same idea _inherit_model already uses for models.”

That’s the key architectural difference to hold onto for the rest of this post: every other extension kind composes (builds a new subclass with a real MRO, so super() works normally). _inherit_mixin patches it mutates the target class or module object directly, in place, exactly once.

Defining a Mixin Extension

from horilla.extension.mixin import MixinExtension




class CustomFieldFilterFieldsExtension(MixinExtension):
    _inherit_mixin = "horilla.contrib.generics.mixins.HorillaListFilterFieldsMixin"


    def _get_model_fields(self, original, *args, **kwargs):
        fields = original(*args, **kwargs)
        fields.extend(get_custom_field_filter_entries(self))
        return fields

The shape looks familiar a class, an _inherit_mixin path, registration on __init_subclass__ but the method signature is different from every other extension kind in this series: def _get_model_fields(self, original, *args, **kwargs). There’s no super() call. original is passed in explicitly, already bound, representing whatever the method did before this extension patched it.

Why No super()?

This is the one firm rule in the whole mechanism, straight from the docs’ rules table:

super() | Do not use it. The target is patched directly, never rebuilt into the extension’s MRO.

The reason is mechanical, not stylistic. Every other extension kind builds a brand-new composed subclass ComposedClass -> Ext2 -> Ext1 -> Target and super() works there because the extension classes are genuinely part of that new MRO (with a closure-cell rebind to make zero-arg super() behave). _inherit_mixin never builds a new class at all. It does a direct setattr() onto the already-existing target class or module:

def apply_mixin_class_extensions(target_class, specs):
    for method_name in ...:
        original = target_class.__dict__.get(method_name) or getattr(target_class, method_name, None)
        setattr(target_class, method_name, _make_chained_method(original, extension_method))

Since the extension’s own class is never part of any inheritance chain the target participates in, super() has nothing correct to resolve to. The explicit original parameter is the only thing standing in for “whatever ran before me” and crucially, it still chains correctly across multiple extensions, because each registration wraps whatever the previous one left behind.

Targeting a Function Instead of a Class

The same mechanism handles bare functions, not just classes:

class CustomFieldExportCellExtension(MixinExtension):
    _inherit_mixin = "horilla.contrib.core.views.export_data.get_export_cell_value"


    def get_export_cell_value(self, original, *args, **kwargs):
        if is_custom_field_cell(args):
            return render_custom_field_cell(*args, **kwargs)
        return original(*args, **kwargs)

Here the method name on the extension class (get_export_cell_value) has to match the function name being overridden exactly that’s validated at registration time (a mismatch is a startup error, mixin_extensions.E004). Under the hood, apply_mixin_function_extensions just reassigns the name on the target module object, so every caller that does from that_module import get_export_cell_value at call time (not a stale import captured earlier) picks up the patched version.

Resolution: There Isn’t Any

This is worth stating plainly because it’s the one package in the whole horilla/extension/ family that doesn’t have a resolve.py file at all. There’s no per-request wrapper, no get_*_class() call, nothing to intercept. Horilla’s own bootstrap docstring says it directly:

Unlike every other _inherit_* package, there is no per-request resolution step here the target itself is never dispatched or resolved by anything. Instead each registered method/function is applied directly onto the target, once.

The patch is applied eagerly, the moment the MixinExtension subclass is defined (registration calls apply_mixin_extensions() immediately after registering), and again from Horilla’s platform-wide bootstrap pass safely idempotent, since each target path tracks which extension specs have already been applied by identity, so re-running the bootstrap doesn’t double-wrap anything.

Because there’s no resolver, there’s also no MRO/base-class fallback built into the extension framework itself but you get one for free anyway, for a more fundamental reason: once HorillaListView.get_queryset is patched on the class object, every subclass of HorillaListView that doesn’t define its own get_queryset inherits the patched version automatically, through ordinary Python attribute lookup. The extension system doesn’t need to walk the hierarchy CPython already does that on every access.

Real Production Usage

This mechanism is genuinely load-bearing, not shelf infrastructure. custom_fields/extensions/mixin.py alone registers eight extensions against it targeting the filter-field dropdown, bulk export, export cell rendering, detail-view field selection, a plain Django form’s __init__, and a condition-builder widget. One example, patching a form’s __init__ directly because FormExtension can’t reach in time:

class CustomFieldColumnSelectionFormExtension(MixinExtension):
    _inherit_mixin = "horilla.contrib.generics.forms.generics.ColumnSelectionForm"


    def __init__(self, original, *args, **kwargs):
        inject_custom_field_choices(self, kwargs)
        original(self, *args, **kwargs)

More tellingly, three other apps use _inherit_mixin against classes that do technically have an as_view() meaning they could have used _inherit_list instead, but chose this mechanism anyway because the behavior needed to apply across every model at once rather than one view at a time:

# horilla/contrib/process/approvals/mixin_extensions.py

class ApprovalListVisibilityExtension(MixinExtension):
    _inherit_mixin = "horilla.contrib.generics.views.list.HorillaListView"


    def get_queryset(self, original, *args, **kwargs):
        queryset = original(*args, **kwargs)
        return exclude_pending_or_rejected_approval(queryset)


# horilla/contrib/process/reviews/list_visibility.py
class ReviewListVisibilityExtension(MixinExtension):
    _inherit_mixin = "horilla.contrib.generics.views.list.HorillaListView"


    def get_queryset(self, original, *args, **kwargs):
        queryset = original(*args, **kwargs)
        return exclude_pending_review(queryset)

Both of these patch HorillaListView.get_queryset independently, from two unrelated apps (approvals and reviews), and they chain correctly each one wraps whatever the other left behind, in priority order. This is a good illustration of the actual tradeoff: _inherit_list targeting the same shared base does support an MRO-aware fallback and composes a real subclass, but _inherit_mixin was the simpler tool to reach for when the behavior genuinely needed to apply blanket-wide, with no per-view customization, no layout hooks, just “every list in the system excludes these rows.”

When to Reach for This Instead of a More Specific Mechanism

The rule of thumb falls out of everything above:

  • If the target has a real resolution point a view’s as_view(), a get_form_class(), a get_filterset_class() use the matching specific mechanism (_inherit_list, _inherit_form, _inherit_filter, etc.). You get proper MRO composition and super() support.
  • If the target is a bare mixin or a bare function with no dispatch point at all, _inherit_mixin is the only option there’s nothing else to hook into.
  • If the target does have a resolution point, but what you need is blanket, model-agnostic behavior across every consumer of a shared base class, with no declarative layout hooks required, _inherit_mixin is still a legitimate, simpler choice as both the approvals and reviews apps demonstrate in production.

_inherit_mixin trades away the things that make the other extension kinds in this series pleasant to use real subclass composition, working super(), declarative append/insert hooks in exchange for being able to reach targets that have no resolution point whatsoever: plain mixins, bare functions, or classes you’d rather patch once for every consumer than compose per-view. The one rule that matters is the explicit original parameter in place of super(); everything else about defining and registering the extension follows the same shape as the rest of the series.

Share this article