Skip to content

Commit d627043

Browse files
committed
fix: move telepath ObjectId adapter registration to AppConfig.ready()
wagtail_hooks.py was never discovered because Wagtail scans using app_config.name (inherited from Wagtail base classes), not the project package name. AppConfig.ready() is the correct Django hook.
1 parent ae88d3b commit d627043

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/dbx_python_cli/templates/project_template/project_name/settings/apps/wagtail.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ class CustomWagtailAdminConfig(WagtailAdminAppConfig):
3838
def default_auto_field(self):
3939
return _auto_field()
4040

41+
def ready(self):
42+
super().ready()
43+
# Register a telepath adapter so MongoDB ObjectId values are serialized
44+
# as their hex string when Wagtail's sidebar builds its JS props.
45+
try:
46+
from bson import ObjectId
47+
from telepath import Adapter
48+
from telepath import register as telepath_register
49+
50+
class _ObjectIdAdapter(Adapter):
51+
def build_node(self, obj, context):
52+
return context.build_node(str(obj))
53+
54+
telepath_register(_ObjectIdAdapter(), ObjectId)
55+
except ImportError:
56+
pass
57+
4158

4259
class CustomWagtailDocsConfig(WagtailDocsAppConfig):
4360
@property

src/dbx_python_cli/templates/project_template/project_name/wagtail_hooks.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)