question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for hybrid_property?

See original GitHub issue

Hello,

I am trying to use hybrid_property as a property on a GraphQL response. However, when I execute the GraphQL request, I am receiving an error stating the property cannot be found.

Are SQlAlchemy hybrid_property attributes currently supported?

Thanks, G

@hybrid_property
    def document_count(self):
        return len(self.linked_documents)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
anisjonischkeitcommented, Feb 21, 2018
# models.py

class Company(Base):
    __tablename__ = 'licence_revisions'

    id = Column(...)
    ...

    licence_states = relationship("Licence", back_populates="company", lazy="dynamic")

    @hybrid_property
    def latest_licence_states(self):
        db_session = object_session(self)

        return self.licence_states \
                   .order_by(Licence.uuid, Licence.revision_id) \
                   .distinct(Licence.uuid).all()

# query.py

class Licence(SQLAlchemyObjectType):
    ...

class Company(SQLAlchemyObjectType):
    class Meta:
        model = models.Company
        interfaces = (graphene.relay.Node, )


    # currently I need these lines to get it to work properly. if I leave them out I
    # just get a string representation of the list of  SQLAlchemy objects:
    # "[<models.Licence object at 0x7f073450ba90>, <models.Licence object at 0x7f073450bb10>]"

    latest_licence_states = SQLAlchemyConnectionField(Licence)
    def resolve_latest_licence_states(self, info):
        return self.latest_licence_states

class Query(graphene.ObjectType):
    node = graphene.relay.Node.Field()

    Company = graphene.Field(Company)
    def resolve_company(self, info):

        query = info.context["session"].query
        company = query(models.Company).get(COMPANY_ID)

        return company

I want to tell graphene-sqlalchemy that the returned type for the hybrid_property is a list of SQLAlchemy objects

1reaction
Salamekcommented, Apr 7, 2021

@anisjonischkeit Just probably late answer to your Q (and help anyone who google this as i did), i had similar problem with hybrid property that returned boolean, but graphene-sqlalchemy was casting it to string ("true" instead of true). Only thing i had to do is set query return type in SQLAlchemyObjectType is_managed = graphene.Boolean():

class Subject(SQLAlchemyObjectType):
    # is_managed is hybrid property so we need to force the type
    is_managed = graphene.Boolean()

    class Meta:
        model = SubjectModel
        interfaces = (relay.Node, )

After this i get correct is_managed: true instead of is_managed: "true" in query response JSON

Not sure if this fix can help with your problem or not, but i guess you should use something like graphene.List(Licence)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hybrid Attributes - SQLAlchemy 1.4 Documentation
“hybrid” means the attribute has distinct behaviors defined at the class level and at the instance level. The hybrid extension provides a special...
Read more >
Equitable Distribution: What is Hybrid Property?
A marital residence is often hybrid property when one party purchased it prior to the marriage with their separate funds, and then the...
Read more >
How to Support the Hybrid Work Model - CommercialSearch
The platform is designed to help occupancy planners oversee the hybrid workplace.
Read more >
What is the difference between marital, separate and hybrid ...
Hybrid property includes assets that may have once been separate, but over time has generated income, increased in value and/or is mixed with...
Read more >
What is "Hybrid" Property and How Is It Divided?
In Virginia, hybrid property (as the name implies) is classified as both marital property and separate property. Some examples include income ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found