Query picking shadowed property when property name is `id` with different column name and second property vice versa.
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
调研方向
先运行提供的 Python/SQLAlchemy/GraphQL 复现代码;它展示了 GraphQL id 与模型的 id 属性之间的不匹配。然后跟踪 Python 属性名与列名不同时 SQLAlchemyObjectType 的字段映射。完成的标准是查询 id 返回 'ham' 而不是 3。
由索引模型根据 Issue 内容生成。
描述
Hello👋,
this works as expected:
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, mapped_column, Mapped, DeclarativeBase
from graphene import Field, ObjectType, Schema
from graphene_sqlalchemy import SQLAlchemyObjectType
class Base(DeclarativeBase):
pass
class Foo(Base):
__tablename__ = "foo"
bar: Mapped[int] = mapped_column(
"spam",
primary_key=True,
)
spam: Mapped[str] = mapped_column("baz")
foo = Foo(bar=3, spam="ham")
engine = create_engine("sqlite:///test.sqlite3")
Base.metadata.create_all(engine)
with Session(engine) as session:
session.add(foo)
session.commit()
class FooNode(SQLAlchemyObjectType):
class Meta:
model = Foo
class Query(ObjectType):
foo = Field(FooNode)
def resolve_foo(self, info):
with Session(engine) as session:
return session.query(Foo).first()
schema = Schema(query=Query)
result = schema.execute(
"""
{
foo {
spam
}
}
"""
)
print(result.data["foo"]["spam"]) # prints 'ham'
but as soon as you change spam to id it prints the value of the property bar:
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, mapped_column, Mapped, DeclarativeBase
from graphene import Field, ObjectType, Schema
from graphene_sqlalchemy import SQLAlchemyObjectType
class Base(DeclarativeBase):
pass
class Foo(Base):
__tablename__ = "foo"
bar: Mapped[int] = mapped_column(
"id",
primary_key=True,
)
id: Mapped[str] = mapped_column("baz")
foo = Foo(bar=3, id="ham")
engine = create_engine("sqlite:///test.sqlite3")
Base.metadata.create_all(engine)
with Session(engine) as session:
session.add(foo)
session.commit()
class FooNode(SQLAlchemyObjectType):
class Meta:
model = Foo
class Query(ObjectType):
foo = Field(FooNode)
def resolve_foo(self, info):
with Session(engine) as session:
return session.query(Foo).first()
schema = Schema(query=Query)
result = schema.execute(
"""
{
foo {
id
}
}
"""
)
print(result.data["foo"]["id"]) # prints 3 but should print 'ham'
I believe that is a bug 🐛
Best, Ueli
- 主要语言
- Python
- 星标
- 985
- 派生
- 224
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/graphene-sqlalchemy 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 25/100
graphql-python/graphene-sqlalchemy#422 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
graphql-python/graphene-sqlalchemy#419 · 3 条评论 ·
查看 graphql-python/graphene-sqlalchemy 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/skills#1811 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
speaches-ai/speaches#678 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
datalayer/mcp-compose#42 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
conda-forge/spacy-feedstock#177 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
UKGovernmentBEIS/inspect_evals#2523 ·