的SQLAlchemy的official documentation指出:Python SQLAlchemy屬性事件 - 如何檢查oldvalue是否等於NO_VALUE?
oldvalue – the previous value being replaced. This may also be the symbol
NEVER_SET
orNO_VALUE
. If the listener is registered withactive_history=True
, the previous value of the attribute will be loaded from the database if the existing value is currently unloaded or expired.
from sqlalchemy import event
# standard decorator style
@event.listens_for(SomeClass.some_attribute, 'set')
def receive_set(target, value, oldvalue, initiator):
"listen for the 'set' event"
# ... (event handling logic) .
我的問題是我怎麼能檢查舊值等於符號NO_VALUE
?
M使用if oldvalue == symbol(NO_VALUE)
但它給了我錯誤。
TypeError: 'module' object is not callable
'如果OLDVALUE是NO_VALUE'? – univerio
@univerio oldvalue是NO_VALUE作品...謝謝..你可以發佈它作爲答案..還記得從sqlalchemy.orm.base導入NO_VALUE – tyan