marshmallow-code / marshmallow-code/apispec-webframeworks

Flask plugin does not gracefully fail when view is None

Open
#133 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
33
Forks
24
Avg merge
5h 38m
Merged PRs (30d)
4

Description

I cannot use spec.path without providing view.

In flask.py:

def path_helper(
        self,
        path: Optional[str] = None,
        operations: Optional[dict] = None,
        parameters: Optional[List[dict]] = None,
        *,
        view: Optional[Union[Callable[..., Any], "RouteCallable"]] = None,
        app: Optional[Flask] = None,
        **kwargs: Any,
    ) -> Optional[str]:
        """Path helper that allows passing a Flask view function."""
        assert view is not None

The assert statement completely fails, this means that if someone was to define multiple plugins for apispec, then because this one fails any time view is not defined, there is no way forward.

Inside core.py inside the apispec, library, they handle any PluginMethodNotImplementedErrors, and move on. I would suggest raising that exception instead.

for plugin in self.plugins:
            try:
                ret = plugin.path_helper(
                    path=path, operations=operations, parameters=parameters, **kwargs
                )
            except PluginMethodNotImplementedError:
                continue

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in flask.py at path_helper and compare its view=None behavior with the PluginMethodNotImplementedError handling shown in core.py. Verify the multi-plugin path-helper flow and confirm that a missing view lets later plugins run without triggering the assertion. Done means the Flask plugin no longer blocks that flow when view is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.