graphql-python / graphql-python/graphene-sqlalchemy
Better approach to `is_mapped_class`
- Linguagem predominante
- Python
- Estrelas
- 985
- Forks
- 223
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
`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
```
Guia de contribuição
Direção de pesquisa
Start in graphene_sqlalchemy.utils.class_mapper and compare its mapper check with the modified recipe from graphene_sqlalchemy/types.py. Verify the change handles deferred relationship callables without forcing configure_mappers, and confirm the existing mapper-detection behavior remains correct.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python, sqlalchemy
- Domínio
- databases
- Tipo de issue
- Refatoração
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 42/100