kvesteri / sqlalchemy-continuum

Versioning extension for SQLAlchemy.
BSD 3-Clause "New" or "Revised" License
580 stars 126 forks source link

'property' object has no attribute 'key' #293

Open aditya051293 opened 2 years ago

aditya051293 commented 2 years ago

My Model setup is something like this.

class Author(BaseModel):
    __tablename__ = "author"
    __versioned__ = {}
    id = Column(Integer, primary_key=True)
    name = Column(String(255))

class Book(BaseModel):
    __tablename__ = "book"
    __versioned__ = {}
    id = Column(Integer, primary_key=True)
    name = Column(String(255))
    author_id = Column(BigInteger, ForeignKey('Author.id'), index=True, nullable=False)
    author = relationship(Author)

I am getting something like this.

getattr(Book, 'author').key author getattr(version_class(Book), 'author').key AttributeError: 'property' object has no attribute 'key'

AbdealiLoKo commented 2 years ago

@aditya051293 The "version" objects don't keep foreign keys and so they don't have relationships. All the values you see like version_class(Book).author are just properties making another query internally All the values you see like Book.author are actual InstrumentedAttribute and RelationshipProperty

As .key is an attribute only available in RelationshipProperty or InstrumentedAttribute - it won't work with the property that sqlalchemy-continuum exposes.