From 2448f2d11cfbc5e548cc159d222b7626b18d872d Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Tue, 3 Jan 2023 12:52:09 +0100 Subject: [PATCH] Make BaseView compatible with Flask 2.2.x The `as_view` method in the latest Flask version doesn't receive any positional argument, since this change: https://github.com/pallets/flask/commit/6e23239567efde1c2e272db87c53444d6c22a1bb This patch makes the code in base compatible with this new version, trying to call the view with the positional argument if present and in other case it's passed as `cls` named argument. This fixes the `test_nested_flask_views` that was broken for this version. --- flask_admin/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flask_admin/base.py b/flask_admin/base.py index e706c916e..39c8654b3 100644 --- a/flask_admin/base.py +++ b/flask_admin/base.py @@ -365,7 +365,10 @@ def _run_view(self, fn, *args, **kwargs): :param kwargs: Arguments """ - return fn(self, *args, **kwargs) + try: + return fn(self, *args, **kwargs) + except TypeError: + return fn(cls=self, **kwargs) def inaccessible_callback(self, name, **kwargs): """