graphql-python / graphql-python/graphene-sqlalchemy

Better approach to `is_mapped_class`

未關閉
#124 0 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
985
分支
223
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

開啟貢獻指南

研究方向

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.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python, sqlalchemy
領域
databases
Issue 類型
重構
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。