2016-09-07 80 views
0

的SQLAlchemy的official documentation指出:Python SQLAlchemy屬性事件 - 如何檢查oldvalue是否等於NO_VALUE?

oldvalue – the previous value being replaced. This may also be the symbol NEVER_SET or NO_VALUE . If the listener is registered with active_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

+1

'如果OLDVALUE是NO_VALUE'? – univerio

+0

@univerio oldvalue是NO_VALUE作品...謝謝..你可以發佈它作爲答案..還記得從sqlalchemy.orm.base導入NO_VALUE – tyan

回答

1

使用

from sqlalchemy.orm.base import NO_VALUE 
if oldvalue is NO_VALUE: 
    //login here 

作品對我來說

0

我覺得應該是if oldvalue is symbol('NO_VALUE'):