Flask-AppBuilder icon indicating copy to clipboard operation
Flask-AppBuilder copied to clipboard

Primary keys need not to be integers, serializing them using int() causes an exception.

Open mapio opened this issue 2 years ago • 0 comments

Environment

Flask-Appbuilder version: 8a18281002d55a50416cf98dad8d75c4c218dbb8

pip freeze output:

apispec==3.3.2 asttokens==2.0.5 attrs==21.4.0 Babel==2.9.1 backcall==0.2.0 black==22.1.0 click==7.1.2 colorama==0.4.4 debugpy==1.5.1 decorator==5.1.1 defusedxml==0.7.1 dnspython==2.2.0 email-validator==1.1.3 entrypoints==0.4 et-xmlfile==1.1.0 executing==0.8.2 Flask==1.1.4 Flask-AppBuilder==3.4.4 Flask-Babel==2.0.0 Flask-JWT-Extended==3.25.1 Flask-Login==0.4.1 Flask-OpenID==1.3.0 Flask-SQLAlchemy==2.5.1 Flask-WTF==0.14.3 greenlet==1.1.2 idna==3.3 importlib-resources==5.4.0 ipykernel==6.9.0 ipython==8.0.1 itsdangerous==1.1.0 jedi==0.18.1 Jinja2==2.11.3 jsonschema==4.4.0 jupyter-client==7.1.2 jupyter-core==4.9.1 MarkupSafe==2.0.1 marshmallow==3.14.1 marshmallow-enum==1.5.1 marshmallow-sqlalchemy==0.26.1 matplotlib-inline==0.1.3 mypy-extensions==0.4.3 nest-asyncio==1.5.4 numpy==1.22.2 openpyxl==3.0.9 pandas==1.4.1 parso==0.8.3 pathspec==0.9.0 pexpect==4.8.0 pickleshare==0.7.5 pkg_resources==0.0.0 platformdirs==2.5.0 prison==0.2.1 prompt-toolkit==3.0.28 ptyprocess==0.7.0 pure-eval==0.2.2 Pygments==2.11.2 PyJWT==1.7.1 pyrsistent==0.18.1 python-dateutil==2.8.2 python3-openid==3.2.0 pytz==2021.3 PyYAML==6.0 pyzmq==22.3.0 six==1.16.0 SQLAlchemy==1.4.31 SQLAlchemy-Utils==0.38.2 stack-data==0.1.4 tomli==2.0.1 tornado==6.1 traitlets==5.1.1 typing_extensions==4.1.1 wcwidth==0.2.5 Werkzeug==1.0.1 WTForms==2.3.3 xlrd==2.0.1 zipp==3.7.0

Describe the expected results

Using a schema with a non-integer primary key should not raise exceptions in any part of the code.

Describe the actual results

If an entity has a string as a primary key, once you try to access it (in edit, list or modify) rises an exception.

Traceback (most recent call last):
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask_appbuilder/security/decorators.py", line 190, in wraps
    return f(self, *args, **kwargs)
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask_appbuilder/views.py", line 457, in api_column_add
    ret_json = self._get_related_column_data(col_name, filter_rel_fields)
  File "/home/santini/.local/share/virtualenvs/dir-panopticon-e274bc7a3ca8ef71524a940630535078/lib/python3.8/site-packages/flask_appbuilder/views.py", line 437, in _get_related_column_data
    ret_list.append({"id": int(pk), "text": str(item)})
ValueError: invalid literal for int() with base 10: 'V06539'

Steps to reproduce

Any schema with a primary key that is not an integer will trigger it.

mapio avatar Feb 16 '22 07:02 mapio