graphql-python / graphql-python/graphene-sqlalchemy

get_query method assumes query is an attribute, fails when its a callable

未关闭
#86 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
985
派生
223
PR 合并指标
30 天内没有已合并 PR

描述

The get_query methods from both SQLAlchemyConnectionField and SQLAlchemyObjectType
assume that the Base model has an attribute **_query_** but if this is a property it will fail.

I have made this changes to fix it in SQLAlchemyConnectionField:
```python
class SQLAlchemyConnectionField(Connection):
@classmethod
def get_query(cls, model, info, **kwargs):
q = get_query(model, info.context)
return q() if callable(q) else q
```

But is probably better to do it in the utils module:
```python
def get_query(model, context):
query = getattr(model, 'query', None)
if not query:
session = get_session(context)
if not session:
raise Exception('A query in the model Base or a session in the schema is required for querying.\n'
'Read more http://graphene-python.org/docs/sqlalchemy/tips/#querying')
query = session.query(model)
else:
query = query() if callable(query) else query
return query
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。