graphql-python / graphql-python/graphene-sqlalchemy
get_query method assumes query is an attribute, fails when its a callable
- Lenguaje dominante
- Python
- Estrellas
- 985
- Forks
- 223
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
```
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.