Query picking shadowed property when property name is `id` with different column name and second property vice versa.
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
調査の方向性
まず、提供されている Python/SQLAlchemy/GraphQL の再現コードを実行する。これは GraphQL id とモデルの id プロパティの不一致を示す。次に、Python プロパティ名とカラム名が異なる場合の SQLAlchemyObjectType のフィールドマッピングを追跡する。id をクエリすると 3 ではなく 'ham' が返されれば完了。
索引モデルが 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphene-sqlalchemy のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
graphql-python/graphene-sqlalchemy#422 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
graphql-python/graphene-sqlalchemy#419 · コメント 3 件 ·
graphql-python/graphene-sqlalchemy の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·