Skip to content

Commit

Permalink
4.1.2 Fixed [#54](#54): Broken on wagtail>=6.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
beatonma committed Jan 30, 2025
1 parent 55c1b33 commit f035f56
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion mentions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "4.1.1"
__version__ = "4.1.2"
__url__ = "https://github.com/beatonma/django-wm/"
8 changes: 7 additions & 1 deletion mentions/helpers/thirdparty/wagtail/resolution.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/tests/test_wagtail/test_with_wagtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f035f56

Please sign in to comment.