graphql-python / graphql-python/graphene-sqlalchemy

Better approach to `is_mapped_class`

Aperta
#124 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
985
Fork
223
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

`sqlalchemy.orm.class_mapper` relies on `sqlalchemy.orm.configure_mappers` to have been called - either explicitly or implicitly by attempting to interact with the mapper. This means that `graphene_sqlalchemy.utils.class_mapper` forces a call to `configure_mappers` – which in turn throws an error unless every model referenced in a deferred callable (i.e. `user = relationship('User')`) has already been discovered.

However, there is another way to determine if a class is a mapper without forcing `configure_mappers`. The recipe is this:

```python
from sqlalchemy.orm import Mapper
from sqlalchemy.exc import NoInspectionAvailable

def is_mapped_class(cls):
'''modified from graphene_sqlalchemy/types.py '''
try:
return isinstance(inspect(cls), Mapper)
except NoInspectionAvailable:
return False
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.