graphql-python / graphql-python/graphene-sqlalchemy

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

オープン
#86 コメント 0 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。