Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Flask.url_for() got multiple values for argument 'self' #5258

Closed
sda97ghb opened this issue Sep 19, 2023 · 2 comments · Fixed by #5264
Closed

TypeError: Flask.url_for() got multiple values for argument 'self' #5258

sda97ghb opened this issue Sep 19, 2023 · 2 comments · Fixed by #5264
Milestone

Comments

@sda97ghb
Copy link

Official documentation doesn't mention any preconditions for values argument, but self=1 raises an exception.

Can be replicated with the following test case:

from unittest import TestCase

from flask import Flask, url_for


class UrlForTests(TestCase):
    def setUp(self) -> None:
        self.app = Flask(__name__)

    def test_with_self_argument(self) -> None:
        with (
            self.app.app_context(),
            self.assertRaisesRegex(
                TypeError, "got multiple values for argument 'self'"
            ),
        ):
            url_for("doesnotmatter", self=1)

Traceback example:

Traceback (most recent call last):
  File "/home/dmitry/git/github.com/minetest/contentdb/tests.py", line 6, in <module>
    url_for("doesnotmatter", self=1)
  File "/home/dmitry/.cache/pypoetry/virtualenvs/contentdb-MK2UWkId-py3.10/lib/python3.10/site-packages/flask/helpers.py", line 256, in url_for
    return current_app.url_for(
TypeError: Flask.url_for() got multiple values for argument 'self'

The expected behavior is the returned URL has query string like '?self=1'.

Environment:

  • Python version: 3.10.6
  • Flask version: 2.3.3
@ThiefMaster
Copy link
Member

Probably self of that method should be made positional-only (unless we still support a Python version that does not support positional-only arguments). As a workaround we could possibly rename it to something like ___self that is almost certainly never used in a real URL param...

@davidism
Copy link
Member

Let's get this into 3.0 and use a position only arg.

@davidism davidism added this to the 3.0.0 milestone Sep 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants