art1415926535 / graphene-sqlalchemy-filter

Filters for Graphene SQLAlchemy integration
https://pypi.org/project/graphene-sqlalchemy-filter/
MIT License
118 stars 34 forks source link

data_loader KeyError when using sqlalchemy 1.4.0b1 #39

Open GeoffreyY opened 3 years ago

GeoffreyY commented 3 years ago

sqlalchemy 1.4.0b1 was released recently, in many ways attempting to serve as a potential migration point for a more dramatic series of API changes currently planned for release 2.0 of SQLAlchemy. The beta version can be installed by passing --pre flag when installing the library, such as:

py -m pip install --pre sqlalchemy

See issue #38 for my test case, with the following changes:

using sqlalchemy version 1.4.0b1 instead of version 1.3.20

My flask client

```python from flask import Flask from flask_graphql import GraphQLView app = Flask(__name__) app.debug = True app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # for having the GraphiQL interface ) ) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': # for this to work in jupyter notebook from werkzeug.serving import run_simple run_simple('localhost', 9000, app) ```

test query

``` query { allSongs { edges { node { name tags { edges { node { name } } } } } } } ```

error in response

``` { "errors": [ { "message": "items", "locations": [ { "line": 6, "column": 9 } ], "path": [ "allSongs", "edges", 0, "node", "tags" ] }, { "message": "items", "locations": [ { "line": 6, "column": 9 } ], "path": [ "allSongs", "edges", 1, "node", "tags" ] }, { "message": "items", "locations": [ { "line": 6, "column": 9 } ], "path": [ "allSongs", "edges", 2, "node", "tags" ] } ], "data": { "allSongs": { "edges": [ { "node": { "name": "素晴らしい日々", "tags": null } }, { "node": { "name": "水槽のフール", "tags": null } }, { "node": { "name": "despacito", "tags": null } } ] } } } ```

server side error

``` An error occurred while resolving field SongNode.tags Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 324, in _get_or_create_data_loader current_data_loader: ModelLoader = data_loaders[data_loader_key] KeyError: ('allSongs', 'edges', 'node', 'tags') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1104, in __getattr__ return self._index[key] KeyError: 'items' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception AttributeError: items Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception graphql.error.located_error.GraphQLLocatedError: items An error occurred while resolving field SongNode.tags Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 324, in _get_or_create_data_loader current_data_loader: ModelLoader = data_loaders[data_loader_key] KeyError: ('allSongs', 'edges', 'node', 'tags') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1104, in __getattr__ return self._index[key] KeyError: 'items' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception AttributeError: items Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception graphql.error.located_error.GraphQLLocatedError: items An error occurred while resolving field SongNode.tags Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 324, in _get_or_create_data_loader current_data_loader: ModelLoader = data_loaders[data_loader_key] KeyError: ('allSongs', 'edges', 'node', 'tags') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1104, in __getattr__ return self._index[key] KeyError: 'items' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception AttributeError: items Traceback (most recent call last): File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphql\execution\executors\sync.py", line 16, in execute return fn(*args, **kwargs) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 356, in connection_resolver data_loader: ModelLoader = cls._get_or_create_data_loader( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 326, in _get_or_create_data_loader current_data_loader = ModelLoader(type(root), model, info, args) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 137, in __init__ self.parent_model_pks: 'Tuple[str, ...]' = self._get_model_pks( File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\graphene_sqlalchemy_filter\connection_field.py", line 197, in _get_model_pks for name, c in inspection.inspect(model).columns.items() File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\sql\base.py", line 1106, in __getattr__ util.raise_(AttributeError(key), replace_context=err) File "c:\users\geoffrey\appdata\local\programs\python\python38\lib\site-packages\sqlalchemy\util\compat.py", line 180, in raise_ raise exception graphql.error.located_error.GraphQLLocatedError: items ```

I feel like this may be related to #38 but I'm not sure, opening a separate issue just in case.