- changed title to mapper has_property method returns False when hybrid_property
mapper has_property method returns False when hybrid_property
Issue #3115
closed
When I try to get property from mapper by name I can't do it when hybrid_property name specified.
import datetime
from sqlalchemy import create_engine, MetaData
from sqlalchemy import Column, String, DateTime, Integer
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import sessionmaker
metadata = MetaData()
Base = declarative_base(metadata=metadata)
class Duration(Base):
__tablename__ = "duration"
pk = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
@hybrid_property
def duration(obj):
return obj.name
engine = create_engine('sqlite:///:memory:', echo=True)
metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
duration = Duration(name="Test")
session.add(duration)
session.commit()
print duration.__mapper__.has_property('duration') # Returns False, needs True
As you can see the has_property('duration') does not see the hybrid_property duration and returns False instead True.
Is it a bug?
Comments (4)
-
reporter -
repo owner - changed status to closed
while there's some poor naming quality going on here, a hybrid is not a
MapperProperty
, which is what the mapper considers to be "properties". To suit the use case where users want to view all class members that are at-all ORM specific, not justMapperProperty
, we have all_orm_descriptors:print "duration" in duration.__mapper__.all_orm_descriptors
-
repo owner - changed milestone to 0.9.8
-
repo owner - changed milestone to 0.9.7
- Log in to comment