Python 在django信号中获取pk_设置值会遇到原子错误
这是我的信号Python 在django信号中获取pk_设置值会遇到原子错误,python,django,Python,Django,这是我的信号 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 奇怪的是,如果我只打印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
奇怪的是,如果我只打印pk_set,我会得到set([1])
,但如果我尝试使用[0]获取实际值,我会遇到:
TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
有没有办法只获得pk_集合号?我只需要身份证
注意:这在测试用例期间发生
奇怪的是,如果我这样做了
list(pk_set)[0]
由于某些原因,这是有效的
list(pk_set)[0]
工作正常,但这不起作用:
pk_set[0]