diff --git a/CHANGELOG.md b/CHANGELOG.md index 0879c33..3464e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ > [!NOTE] > Release notes are also available on the [wiki](https://github.com/beatonma/django-wm/wiki/Releases). + +## 4.1.2 (2025-01-30) +- Fixed [#54](https://github.com/beatonma/django-wm/issues/54): Broken on `wagtail>=6.2`. + - Issue: In `wagtail==6.2`, the implementation of `RoutablePageMixin.route` was changed to add the `routable_resolver_match` attribute to the given request object. `get_model_for_url_by_wagtail` previously called that method with `request=None` (because there is no relevant request object available at the time webmentions are processed), so trying to set that attribute on the request fails. + - Fix: `get_model_for_url_by_wagtail` now creates and passes a dummy instance of `HttpRequest` when calling that method. + + ## 4.1.1 (2024-02-10) > [!WARNING] diff --git a/mentions/__init__.py b/mentions/__init__.py index f503e5c..7b36db2 100644 --- a/mentions/__init__.py +++ b/mentions/__init__.py @@ -1,2 +1,2 @@ -__version__ = "4.1.1" +__version__ = "4.1.2" __url__ = "https://github.com/beatonma/django-wm/" diff --git a/mentions/helpers/thirdparty/wagtail/resolution.py b/mentions/helpers/thirdparty/wagtail/resolution.py index 0cc8081..086d5a7 100644 --- a/mentions/helpers/thirdparty/wagtail/resolution.py +++ b/mentions/helpers/thirdparty/wagtail/resolution.py @@ -1,6 +1,7 @@ from typing import Callable, Optional, Type from django.apps import apps +from django.http import HttpRequest from django.urls import ResolverMatch from mentions import config, contract, options @@ -39,7 +40,12 @@ def get_model_for_url_by_wagtail(match: ResolverMatch) -> MentionableMixin: path = match.args[0] path_components = [component for component in path.split("/") if component] - page, args, kwargs = site.root_page.localized.specific.route(None, path_components) + dummy_request = HttpRequest() + dummy_request.method = "GET" + dummy_request.path = path + page, args, kwargs = site.root_page.localized.specific.route( + dummy_request, path_components + ) if isinstance(page, MentionableMixin): return page diff --git a/tests/tests/test_wagtail/test_with_wagtail.py b/tests/tests/test_wagtail/test_with_wagtail.py index b22bbbe..e2b4c48 100644 --- a/tests/tests/test_wagtail/test_with_wagtail.py +++ b/tests/tests/test_wagtail/test_with_wagtail.py @@ -27,6 +27,7 @@ from tests.test_wagtail_app.models import IndexPage, MentionablePage, SimplePage except ImportError: Page = None + SimplePage = None Site = None IndexPage = None MentionablePage = None