graphql-python / graphql-python/graphene-sqlalchemy

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

Offen
#86 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
985
Forks
223
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.