Skip to content

Commit ae88d3b

Browse files
committed
feat: register telepath ObjectId adapter in project template
Wagtail's sidebar serializes page IDs via telepath, which has no built-in handler for MongoDB ObjectId. This adds wagtail_hooks.py to the project template that overrides build_node to delegate to telepath's string primitive handler, fixing the UnpackableTypeError at /cms/ on first load.
1 parent 1851e40 commit ae88d3b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from bson import ObjectId
2+
from telepath import Adapter, register
3+
4+
5+
class ObjectIdAdapter(Adapter):
6+
"""Serialize MongoDB ObjectId as its hex string for telepath/JS."""
7+
8+
def build_node(self, obj, context):
9+
return context.build_node(str(obj))
10+
11+
12+
register(ObjectIdAdapter(), ObjectId)

0 commit comments

Comments
 (0)