Query picking shadowed property when property name is `id` with different column name and second property vice versa.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Run the supplied Python/SQLAlchemy/GraphQL reproduction first; it demonstrates the mismatch between GraphQL id and the model's id property. Then trace SQLAlchemyObjectType's field mapping when Python property and column names differ. Done means querying id returns 'ham' rather than 3.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 985
- Forks
- 224
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene-sqlalchemy
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
graphql-python/graphene-sqlalchemy#422 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
graphql-python/graphene-sqlalchemy#419 · 3 comments ·
All issues in graphql-python/graphene-sqlalchemy
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·