diff --git a/src/django_components/context.py b/src/django_components/context.py index 1c3d0636..c52c9be5 100644 --- a/src/django_components/context.py +++ b/src/django_components/context.py @@ -5,6 +5,7 @@ pass data across components, nodes, slots, and contexts. You can think of the Context as our storage system. """ +from copy import copy from typing import TYPE_CHECKING, Optional from django.template import Context @@ -84,7 +85,7 @@ def capture_root_context(context: Context) -> None: """ root_ctx_already_defined = _OUTER_CONTEXT_CONTEXT_KEY in context if not root_ctx_already_defined: - set_root_context(context, context.__copy__()) + set_root_context(context, copy(context)) def set_slot_component_association(context: Context, slot_id: str, component_id: str) -> None: diff --git a/src/django_components/slots.py b/src/django_components/slots.py index a13bd219..cdaa21d0 100644 --- a/src/django_components/slots.py +++ b/src/django_components/slots.py @@ -1,5 +1,6 @@ import difflib import json +from copy import copy from typing import Dict, List, NamedTuple, Optional, Set, Type, Union from django.template import Context, Template @@ -145,7 +146,7 @@ class SlotNode(Node): elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.ISOLATED: return root_ctx elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.PREFER_ROOT: - new_context: Context = context.__copy__() + new_context: Context = copy(context) new_context.update(root_ctx.flatten()) return new_context else: