pallets-eco / flask-security

Quick and simple security for Flask applications
MIT License
649 stars 154 forks source link

Wrong module/type in the role and user table when using flask db migrate #1030

Closed yjcb22 closed 1 month ago

yjcb22 commented 1 month ago

Using the default models for Role and User is generating a migration with flask_security.datastore.AsaList() consequently SQLALchemy cannot apply the db upgrade as follows:

image image image

My understanding based on the documentation is that flask_security.datastore.AsaList() is based on SQLAlchemy MutableList so it should be used as

permissions = Column(MutableList.as_mutable(AsaList()), nullable=True)

image

yjcb22 commented 1 month ago

One quick way to fix it (probably not the best one since it breaks the flow) is to import the module:

image

jwag956 commented 1 month ago

Not sure why Alembic would generate that - but as Alembic suggests - change the generated code if necessary - in this case I would:

from flask_security import AsaList

sa.Column('permissions', AsaList(), nullable=True)
yjcb22 commented 1 month ago

Thanks @jwag956 !