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

Cannot create_role - permissions trying to save as list #673

Closed
janpeterka opened this issue Sep 19, 2022 · 3 comments · Fixed by #675
Closed

Cannot create_role - permissions trying to save as list #673

janpeterka opened this issue Sep 19, 2022 · 3 comments · Fixed by #675
Assignees
Labels

Comments

@janpeterka
Copy link

After updating to 5.0.1 (from 4.1.4), my tests are failing.

I create roles as:

        security.datastore.create_role(
            name="admin",
            permissions="manage-application,manage-users,login-as,see-debug,see-other,edit-other",
        ),

but when I print it, it says role.permissions is ['manage-application', 'manage-users', 'login-as', 'see-debug', 'see-other', 'edit-other']
and when saving (tried SQLite and MySQL), I get error:
in SQLite:

SQLAlchemy: Error binding parameter 0 - probably unsupported type

and in MySQL (PyMySQL)

ERROR    app:base_mixin.py:98 Save error: (pymysql.err.OperationalError) (1241, 'Operand should contain 1 column(s)')
[SQL: INSERT INTO roles (permissions, name, description) VALUES (%(permissions)s, %(name)s, %(description)s)]
[parameters: {'permissions': ['manage-application', 'manage-users', 'login-as', 'see-debug', 'see-other', 'edit-other'], 'name': 'admin', 'description': None}]
(Background on this error at: https://sqlalche.me/e/14/e3q8)

My role model is defined as:

from flask_security.models.fsqla_v2 import FsRoleMixin as RoleMixin

class Role(BaseModel, BaseMixin, RoleMixin, BasePresenter):
    __tablename__ = "roles"

    id = db.Column(db.Integer(), primary_key=True)  # type: ignore
    name = db.Column(db.String(80), unique=True)  # type: ignore
    description = db.Column(db.String(255))  # type: ignore

I've read v5.0.0 changelog concerning this (https://flask-security-too.readthedocs.io/en/stable/changelog.html#version-5-0-0), but it seems like the permission list should be converted to string when saving to db, shouldn't it?

@jwag956
Copy link
Collaborator

jwag956 commented Sep 19, 2022

Bummer - I must have missed some backwards compat - if you can - change your DB models to inherit from models.fsqlav3 and that should get things working. If that isn't practical give me a few days to patch this - I didn't intend to break fsqlav2 projects..

@jwag956 jwag956 self-assigned this Sep 19, 2022
@jwag956 jwag956 added the bug label Sep 19, 2022
@janpeterka
Copy link
Author

Thanks, will try that!

jwag956 added a commit that referenced this issue Sep 21, 2022
Now - if an app uses fsqla_vX it just works.
Added description in CHANGES on how apps that don't use fsqla_vX need to be modified.

Added some tests to verify working with older DBs.

The fsqlalchemy example was crazy - trying to use mocks made everything very complex. Converted to a simpler in-memory DB style testing.

closes #673
@jwag956 jwag956 mentioned this issue Sep 21, 2022
jwag956 added a commit that referenced this issue Sep 22, 2022
Now - if an app uses fsqla_vX it just works.
Added description in CHANGES on how apps that don't use fsqla_vX need to be modified.

Added some tests to verify working with older DBs.

The fsqlalchemy example was crazy - trying to use mocks made everything very complex. Converted to a simpler in-memory DB style testing.

closes #673
jwag956 added a commit that referenced this issue Sep 22, 2022
Now - if an app uses fsqla_vX it just works.
Added description in CHANGES on how apps that don't use fsqla_vX need to be modified.

Added some tests to verify working with older DBs.

The fsqlalchemy example was crazy - trying to use mocks made everything very complex. Converted to a simpler in-memory DB style testing.

closes #673
jwag956 added a commit that referenced this issue Sep 22, 2022
* Fix backwards compat issues with permissions.

Now - if an app uses fsqla_vX it just works.
Added description in CHANGES on how apps that don't use fsqla_vX need to be modified.

Added some tests to verify working with older DBs.

The fsqlalchemy example was crazy - trying to use mocks made everything very complex. Converted to a simpler in-memory DB style testing.

closes #673
@jwag956
Copy link
Collaborator

jwag956 commented Sep 23, 2022

I just pushed 5.0.2 - with that, and the fact that you are using fsqla_v2 in your models - you should need NO changes to get permissions working.

Thanks for your patience.

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

Successfully merging a pull request may close this issue.

2 participants