Query picking shadowed property when property name is `id` with different column name and second property vice versa.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Trước tiên, hãy chạy bản tái hiện Python/SQLAlchemy/GraphQL được cung cấp; bản này cho thấy sự không khớp giữa GraphQL id và thuộc tính id của model. Sau đó, hãy lần theo ánh xạ field của SQLAlchemyObjectType khi tên thuộc tính Python và tên column khác nhau. Được xem là hoàn tất khi truy vấn id trả về 'ham' thay vì 3.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 985
- Fork
- 224
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql-python/graphene-sqlalchemy
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
graphql-python/graphene-sqlalchemy#422 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
graphql-python/graphene-sqlalchemy#419 · 3 bình luận ·
Tất cả issue của graphql-python/graphene-sqlalchemy
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·