2017-09-13 8 views
0

原子エラーに遭遇し取得pk_set値は、これは私の信号である

def my_signal(instance, action, pk_set, **kwrags): 
    instance.animal_count = instance.animals.all().count() 
    instance.save() 
    if action == 'post_add': 
     print pk_set #works 
     print pk_set[0] #no work 

私はちょうど私がset([1])を得るpk_set印刷するが、私はしようと、[使用して0を実際の値を取得する場合は奇妙なことは、あります]私は以下を実行します:

TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block. 

pk_set番号を取得する方法はありますか?私は文字通り、IDだけが必要です。

注:これはテストケースで発生します。

私は

list(pk_set)[0] 

をすれば、これは

list(pk_set)[0] 

作品をやって、いくつかの理由から

答えて

0

に動作しますが、これにはない奇妙なこと:

pk_set[0] 
関連する問題