Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Query picking shadowed property when property name is `id` with different column name and second property vice versa.

Open
#412 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
graphql, python, sqlalchemy, sqlite
Domain
api, backend, databases

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphene-sqlalchemy

All issues in graphql-python/graphene-sqlalchemy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.