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

Compatibility problems between 0.9 - 0.10? #796

Closed
rplopes opened this issue Jul 9, 2013 · 18 comments
Closed

Compatibility problems between 0.9 - 0.10? #796

rplopes opened this issue Jul 9, 2013 · 18 comments

Comments

@rplopes
Copy link

rplopes commented Jul 9, 2013

I'm getting the following error in flask 0.10:

AssertionError: View function mapping is overwriting an existing endpoint function: etc

The other members of the project, who have configured their environment earlier, are not getting this error. The requirements.txt file is requesting flask 0.9, but whenever I try to install that version, I end up having 0.10.

So I'm assuming that the difference between their environment and mine is that version number (since that error is related to flask). So are there new features in 0.10 that break apps developed for 0.9? And how can I install 0.9? It looks like the 0.9 branch is missing in the repo.

@gregorynicholas
Copy link

same as #795 ?

@rplopes
Copy link
Author

rplopes commented Jul 9, 2013

The root cause seems to be the same. The odd part is that it is working in other setups. Right now I think it might be related to some change between 0.9 and 0.10. But I have no access to the 0.9 version to test it.

@ajford
Copy link

ajford commented Jul 9, 2013

Check out #794, it looks like you may be running into the 'feature' introduced by the fix for issue #570. I have code written for Flask 0.8 that breaks when I try to use 0.10.

To resolve #570, an assertion was added that conflicts with anything that causes two endpoints to have the same apparent name. There is a fix in the dev release that may work for you if you aren't using method views. Otherwise you may need to force pip to use 0.9.

@rplopes
Copy link
Author

rplopes commented Jul 10, 2013

Thank you, #794 really seems to be about the same issue. I've been trying to force pip to use 0.9, but it will download 0.10 anyway. Don't know if something's wrong with 0.9. I'll try to install 0.8 then and see if it fixes it.

@rplopes
Copy link
Author

rplopes commented Jul 10, 2013

Trying to install 0.8 through pip also resulted in installing 0.10. So I installed it through the repo code. So for reference, if somebody wants to solve this problem:

git clone http://github.com/mitsuhiko/flask.git
git checkout -b 0.8 origin/0.8-maintenance
python setup.py develop

So my problem was solved and the issue in 0.10 is already described in #794. The only remaining problem is that trying to install older versions through pip doesn't work. Don't know if that's a problem with flask or pip, so don't know if this issue may be closed already.

@mitsuhiko
Copy link
Contributor

Note that this is not a bug, it's intended behavior and will not change. If you run into this you are probably causing a bug somewhere. Can you give a testcase for how you trigger it?

@sibblegp
Copy link

Why would this be intended behavior? For example, I am using Flask-Restless and want two endpoints URIs to point to the same view function. I iterate through a list of the URIs and as I add resources, I get this error since they are pointing to the same function.

What is the advantage created by this over the previous behavior?

@untitaker
Copy link
Contributor

@sibblegp This code will now raise an exception:

@app.route('/')
def foo():
    return "index"

@app.route('/foo')
def foo():
    return "foo"

When i use Flask 0.9, the code above will return "foo" for requesting "/".

@sibblegp
Copy link

Okay, I see the issue. However, that's a namespace problem where you have two functions conflicting against each other. I should still be able to map a view function to as many routes as I want. This is kind of solving it in the wrong way IMHO.

@cybertoast
Copy link
Contributor

Sorry to dredge up an old issue, but does this mean that I can't have multiple routes go to the same function? Eg.

GET /users
GET /users/show
both going to the same function:

@app.route('/show', methods=['GET'])
@app.route('/', methods=['GET'])
def show():
return get_users()

I thought this was allowed practice (and have applications that have this in place). If this is now disallowed, is the only way to retain this functionality by downgrading to 0.8?

Thanks much

@ThiefMaster
Copy link
Member

@cybertoast : You can still do that. It's allowed unless you try to use the same endpoint name for two different functions (which usually is a copy&paste bug)

@chaosagent
Copy link
Contributor

Okay I'm using a decorator to wrap my api functions like:

@route('/api/thing')
@tools.api.response
def thing():
    stuff

tools.api.response returns a function that wraps stuff around thing, so im getting this error.

@davidism
Copy link
Member

davidism commented Apr 6, 2015

@chaosagent without seeing your decorator, that isn't a very useful message, but you're probably not using functools.wraps to produce the decorated function.

@chaosagent
Copy link
Contributor

@davidism Thanks, but that ended up not having a name attribute altogether.
I solved my problem by doing:

def response(func):
    def wrapper(*args, **kwargs):
        stuff
    wrapper.__name__ = func.__name__
    return wrapper

@ThiefMaster
Copy link
Member

from functools import wraps

def response(func):
    @wraps(func)
    def wrapper(args, *kwargs):
        stuff
    return wrapper

@chaosagent
Copy link
Contributor

@ThiefMaster Thanks, that worked.
I really need to read documentation more carefully...

@tuukkamustonen
Copy link

Why exactly is endpoint property needed? Why isn't route -> view mapping enough?

Trying something like:

class SomeMiddleware:
    def __init__(self, app, path):
        self.app = app
        app.add_url_rule(path, view_func=self.run)

    def run(self):
        ...

app = Flask()
SomeMiddleware('/path1', app)
SomeMiddleware('/path2', app)  # raises this error

How should this be tackled - have caller provide endpoint name? Or generate UUID as it? Or use route (hash) as endpoint name?

@tuukkamustonen
Copy link

tuukkamustonen commented Mar 20, 2018

Nevermind, while I didn't find this from Flask docs, it's well described here: https://stackoverflow.com/a/19262349/165629. So I guess if there's no harm doing endpoint=random_string() if I don't need url_for.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests