Search code examples
pythonflaskflask-sqlalchemyflask-wtformsflask-appbuilder

Flask-Appbuilder Model Relations Using UUID


I'm working on an application which will be defining several models that will be using the UUIDType from scqlalchemy_utils package, defining views like this:

class ChildModelAView(ModelView):
    datamodel = SQLAInterface(ChildA)
    list_columns = ['title', 'description', 'parent_model']

class ChildModelBView(ModelView):
    datamodel = SQLAInterface(ChildB)
    list_columns = ['title', 'description', 'parent_model']

class ParentModelView(ModelView):
    datamodel = SQLAInterface(Parent)
    related_views = [ChildModelAView, ChildModelBView]

And my models like this:

class ChildA(Model):
    id = Column(UUIDType(binary=False), default=uuid.uuid4, primary_key=True)
    parent_id = Column(UUIDType(binary=False), ForeignKey('parent.id'), nullable=False)
    parent = relationship('Parent')


class ChildB(Model):
    id = Column(UUIDType(binary=False), default=uuid.uuid4, primary_key=True)
    parent_id = Column(UUIDType(binary=False), ForeignKey('parent.id'), nullable=False)
    parent = relationship('Parent')

class Parent(Model):
    id = Column(UUIDType(binary=False), default=uuid.uuid4, primary_key=True)

I see this warning for all the columns defined as a UUID when starting the application:

2018-02-02 19:08:39,244:WARNING:flask_appbuilder.models.filters:Filter type not supported for column: id
2018-02-02 19:08:39,244:WARNING:flask_appbuilder.models.filters:Filter type not supported for column: parent_id

Can anyone show me a working example or snippet that allows filtering with a UUID type (or other custom) column? Everything else using this type seems to work correctly.

Thanks!


Solution

  • In case anyone else stumbles upon this same issue, there seems to be a solution in the works for FAB itself.

    Here's the PR that should resolve this problem: https://github.com/dpgaspar/Flask-AppBuilder/pull/694