属性装饰器函数是否仅在调用时才执行?

时间:2018-04-30 23:07:11

标签: python sqlalchemy

我想知道requiresQuery是否只会在被调用时执行,或者只在您对该表进行查询时执行。

class SomeTable(Base):
    ...
    someJson = Column(Text)
    ...
    @property
    def requiresQuery(self):
        filterValue = getValueFromJson(self.someJson)
        someQuery = session.query(OtherTable).filter(OtherTable.filter == filterValue)
        return getValue(someQuery)

现在使用该表:

# Query SomeTable and never ask for the value
session.query(SomeTable).one().someJson
# Does the requiresQuery execute here?
# Or does it need to be called explicitly
session.query(SomeTable).one().requiresQuery
# requiresQuery has been called here. 

0 个答案:

没有答案