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

cognito_group_permissions not working #16

Open
bractus opened this issue Sep 25, 2020 · 6 comments
Open

cognito_group_permissions not working #16

bractus opened this issue Sep 25, 2020 · 6 comments

Comments

@bractus
Copy link

bractus commented Sep 25, 2020

I'm trying to use the cognito_group_permissions decorator but isn't working...

Traceback (most recent call last):
File "main.py", line 5, in
from flask_cognito import CognitoAuth, cognito_group_permissions
ImportError: cannot import name 'cognito_group_permissions' from 'flask_cognito' (C:\Users\Cairo\anaconda3\envs\salt\lib\site-packages\flask_cognito.py)

@revmischa
Copy link
Member

@aaronbrown1988

@aaronbrown1988
Copy link
Contributor

Had a quick look, seems like the name of the decorator in the module doesn't match that in the read me. It's looks to have been mismatched since ~ PR #9. I've made a branch which duplicates the decorator under the name that matches the readme me and adds a few tests, alternatively the readme could be updated to reflect the name in the code.

@revmischa how do you want to handle the mismatch between the name in the code in the readme to avoid breaking things for other users who might be using the current decorator name?

@aaronbrown1988
Copy link
Contributor

@revmischa
Copy link
Member

Up to you, can you just export a variable that is an alias of the existing decorator?

@aaronbrown1988
Copy link
Contributor

Sure, that would work. I've created a PR with the change here: #17

@MordiGrip
Copy link
Contributor

Hi, I have encountered the same issue, in a slightly different way.

First of all, @aaronbrown1988 thanks for your solution!

But I'm afraid it's not enough, you see, the decorator generator always returns the same function and that's lead to the same function being registered on different flask routes (which is impossible).

so I think we should change this code:

def cognito_check_groups(groups: list):
    def decorator(function):
        def wrapper(*args, **kwargs):
            _cognito_check_groups(groups)
            return function(*args, **kwargs)

        return wrapper

    return decorator

to use python wraps like the other generators, so it will look roughly like this:

def cognito_check_groups(groups: list):
    def decorator(function):
        @wraps(function)
        def wrapper(*args, **kwargs):
            _cognito_check_groups(groups)
            return function(*args, **kwargs)

        return wrapper

    return decorator

This way the wrapper function will be patched to have the original metadata.

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

No branches or pull requests

4 participants