Skip to content

Commit 39cab12

Browse files
committed
Catch the wrapt __reduce_ex__ NotImplemented error that gets throw when a component uses the db_model decorator.
1 parent a65e157 commit 39cab12

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

django_unicorn/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,9 @@ def get_cacheable_component(component):
6161
raise UnicornCacheError(
6262
"Cannot cache component because it is not picklable."
6363
) from e
64+
except NotImplementedError as e:
65+
raise UnicornCacheError(
66+
"Cannot cache component because it is not picklable."
67+
) from e
6468

6569
return component

tests/decorators/test_db_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django_unicorn.components import UnicornView
44
from django_unicorn.db import DbModel
55
from django_unicorn.decorators import db_model
6+
from django_unicorn.errors import UnicornCacheError
7+
from django_unicorn.utils import get_cacheable_component
68
from example.coffee.models import Flavor
79

810

@@ -78,3 +80,12 @@ class Meta:
7880

7981
with pytest.raises(AssertionError):
8082
component.get_pk({"name": "flavor", "pk": -99})
83+
84+
85+
@pytest.mark.django_db
86+
def test_component_db_model_not_pickleable(component):
87+
"""
88+
This is not ideal and should hopefully be fixable by providing a `__reduce_ex__` method.
89+
"""
90+
with pytest.raises(UnicornCacheError):
91+
get_cacheable_component(component)

0 commit comments

Comments
 (0)