graphql-python / graphql-python/graphene-sqlalchemy
get_query method assumes query is an attribute, fails when its a callable
- 主要語言
- 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
```
貢獻指南
研究方向
Read the existing get_query implementation in the utils module and the get_query methods on SQLAlchemyConnectionField and SQLAlchemyObjectType. Check how model.query and session-based queries are obtained, then verify that both attribute and callable query providers work without changing the existing missing-query error behavior.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- graphql, python, sqlalchemy
- 領域
- backend-api-design, database
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100