dpgaspar / Flask-AppBuilder

Simple and rapid application development framework, built on top of Flask. includes detailed security, auto CRUD generation for your models, google charts and much more. Demo (login with guest/welcome) - http://flaskappbuilder.pythonanywhere.com/
BSD 3-Clause "New" or "Revised" License
4.65k stars 1.36k forks source link

Unable to register Add-on Views using ADDON_MANAGERS #1915

Closed christyxgeorge closed 2 years ago

christyxgeorge commented 2 years ago

I am running Superset 2.0 with Flask-AppBuilder==4.1.3 While configuring ADDON_MANAGERS as such, --- ADDON_MANAGERS = ['tag_addon_manager.TagAddOnManager']

i get the following error.

File "/Users/xyz/lib/python3.9/site-packages/flask_appbuilder/base.py", line 335, in _add_addon_views NameError: name 'BaseManager' is not defined 2022-08-28 10:34:32,546:ERROR:superset.app:Failed to create app

My Analysis...

Based on the attached traceback... I noticed that line # 335 in flask_appbuilder/base.py is ...

       addon_class = cast(Type[BaseManager], addon_class_)

I suspect, the error is because BaseManager is only imported if running under TYPE_CHECKING (line # 25, 26). if TYPE_CHECKING: from flask_appbuilder.basemanager import BaseManager

I think, the line # 335 should be modified to

       addon_class = cast(Type["BaseManager"], addon_class_)

But, i am not sure given that this is my first experience with flask_appbuilder. Do let me know and i can raise a PR.

Responsible disclosure: We want to keep Flask-AppBuilder safe for everyone. If you've discovered a security vulnerability please report to danielvazgaspar@gmail.com.

Environment: Mac OSX Monterey (v12.4)

Flask-Appbuilder version: Flask-AppBuilder==4.1.3

pip freeze output:

aiohttp==3.8.1 aiosignal==1.2.0 alembic==1.8.1 amqp==5.1.1 apache-superset @ file://localhost//Users/xyz/Teamstreamz/dev/superset apispec==3.3.2 apsw==3.39.2.0 astroid==2.11.7 async-generator==1.10 async-timeout==4.0.2 attrs==22.1.0 Babel==2.10.3 backoff==2.1.2 billiard==3.6.4.0 black==22.6.0 bleach==3.3.1 blinker==1.5 boto3==1.24.55 botocore==1.27.55 Brotli==1.0.9 cachelib==0.4.1 cachetools==5.2.0 celery==5.2.7 certifi @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_83242e7e-f82d-4a71-8ef2-9d71d212d249gu_wxmeq/croots/recipe/certifi_1655968827803/work/certifi cffi==1.15.1 charset-normalizer==2.1.0 click==8.1.3 click-didyoumean==0.3.0 click-plugins==1.1.1 click-repl==0.2.0 colorama==0.4.5 console-log==0.2.10 convertdate==2.4.0 cron-descriptor==1.2.31 croniter==1.3.5 cryptography==37.0.4 db-dtypes==1.0.3 Deprecated==1.2.13 deprecation==2.1.0 dill==0.3.5.1 dnspython==2.2.1 docker==6.0.0 email-validator==1.2.1 emoji==2.0.0 Flask==2.1.3 Flask-AppBuilder==4.1.3 Flask-Babel==2.0.0 Flask-Caching==1.11.1 Flask-Compress==1.12 Flask-JWT-Extended==4.4.4 Flask-Login==0.6.2 Flask-Migrate==3.1.0 Flask-SQLAlchemy==2.5.1 flask-talisman==1.0.0 Flask-WTF==0.15.1 frozenlist==1.3.1 func-timeout==4.3.5 future==0.18.2 geographiclib==1.52 geopy==2.2.0 gevent==21.12.0 gevent-websocket==0.10.1 google-api-core==2.8.2 google-auth==2.10.0 google-auth-oauthlib==0.5.2 google-cloud-bigquery==3.3.2 google-cloud-bigquery-storage==2.14.2 google-cloud-core==2.3.2 google-crc32c==1.3.0 google-resumable-media==2.3.3 googleapis-common-protos==1.56.4 graphlib-backport==1.0.3 greenlet==1.1.2 grpcio==1.47.0 grpcio-status==1.47.0 gunicorn==20.1.0 h11==0.13.0 hashids==1.3.1 hijri-converter==2.2.4 holidays==0.14.2 humanize==4.3.0 idna==3.3 importlib-metadata==4.12.0 isodate==0.6.1 isort==5.10.1 itsdangerous==2.1.2 Jinja2==3.1.2 jmespath==1.0.1 jsonschema==4.12.1 kombu==5.2.4 korean-lunar-calendar==0.2.1 lazy-object-proxy==1.7.1 Mako==1.2.1 Markdown==3.4.1 MarkupSafe==2.1.1 marshmallow==3.17.0 marshmallow-enum==1.5.1 marshmallow-sqlalchemy==0.26.1 mccabe==0.7.0 msgpack==1.0.4 multidict==6.0.2 mypy-extensions==0.4.3 mysqlclient==2.1.1 numpy==1.22.1 oauthlib==3.2.0 outcome==1.2.0 packaging==21.3 pandas==1.4.3 pandas-gbq==0.17.8 parsedatetime==2.6 pathspec==0.9.0 pgsanity==0.2.9 Pillow==9.2.0 platformdirs==2.5.2 polyline==1.4.0 prison==0.2.1 prompt-toolkit==3.0.30 proto-plus==1.22.0 protobuf==4.21.5 pyarrow==6.0.1 pyasn1==0.4.8 pyasn1-modules==0.2.8 pyathena==2.3.2 pybigquery==0.10.2 pycparser==2.21 pydata-google-auth==1.4.0 PyJWT==2.4.0 pylint==2.14.5 PyMeeus==0.5.11 pyparsing==3.0.9 pyrsistent==0.18.1 PySocks==1.7.1 python-dateutil==2.8.2 python-dotenv==0.20.0 python-geohash==0.8.5 pytz==2022.2.1 PyYAML==6.0 redis==4.3.4 requests==2.28.1 requests-oauthlib==1.3.1 rsa==4.9 s3transfer==0.6.0 s3werkzeugcache==0.2.1 selenium==4.4.3 shillelagh==1.1.0 simplejson==3.17.6 six==1.16.0 slackclient==2.5.0 sniffio==1.2.0 sortedcontainers==2.4.0 SQLAlchemy==1.4.40 SQLAlchemy-Utils==0.37.9 sqlparse==0.3.0 tabulate==0.8.9 tenacity==8.0.1 tomli==2.0.1 tomlkit==0.11.4 trio==0.21.0 trio-websocket==0.9.2 typing-extensions==3.10.0.2 urllib3==1.26.11 vine==5.0.0 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.3.3 Werkzeug==2.0.3 wrapt==1.14.1 wsgigzip==0.1.4 wsproto==1.1.0 WTForms==2.3.3 WTForms-JSON==0.3.5 yarl==1.8.1 zipp==3.8.1 zope.event==4.5.0 zope.interface==5.4.0

Describe the expected results

The ADDON views should have been configured and be visible in the SUperset Web console (under the Settings Menu)

Paste a minimal example that causes the problem.

Adding the following line in superset_config.py

ADDON_MANAGERS = ['tag_addon_manager.TagAddOnManager']

Describe the actual results

Not applicable... There is an exception thrown as show above...

Paste the full traceback if there was an exception.

Failed to create app Traceback (most recent call last): File "/Users/xyz/lib/python3.9/site-packages/superset/app.py", line 37, in create_app app_initializer.init_app() File "/Users/xyz/lib/python3.9/site-packages/superset/initialization/init.py", line 465, in init_app self.init_app_in_ctx() File "/Users/xyz/lib/python3.9/site-packages/superset/initialization/init.py", line 413, in init_app_in_ctx self.configure_fab() File "/Users/xyz/lib/python3.9/site-packages/superset/initialization/init.py", line 509, in configure_fab appbuilder.init_app(self.superset_app, db.session) File "/Users/xyz/lib/python3.9/site-packages/flask_appbuilder/base.py", line 219, in init_app self._add_addon_views() File "/Users/xyz/lib/python3.9/site-packages/flask_appbuilder/base.py", line 335, in _add_addon_views addon_class = cast(Type[BaseManager], addonclass)

Steps to reproduce

Run the command:

superset shell

dpgaspar commented 2 years ago

Thank you for reporting this. It does seem like a regression. I'll make a fix ASAP

christyxgeorge commented 2 years ago

Thanks @dpgaspar

dpgaspar commented 2 years ago

fixed is merged to master, it will be out on the next release