Django和芹菜的dotnotexists错误



以下是基本芹菜代码

 @app.task
 def t_select(booking_id, seat_id, user_id):
     with transaction.atomic():
         booking = Booking.objects.get(id=booking_id)
         booking.seats.add(Seat.objects.get(pk=seat_id))
         return booking.save()

给出以下错误:

[2018-04-01 02:25:55,893: INFO/MainProcess] Received task: functors.booker.t_select[cec7f2ca-bca0-4f3e-9865-102f3528ce3a]  
[2018-04-01 02:25:55,894: ERROR/ForkPoolWorker-4] Task functors.booker.t_select[e3a69d6b-1fc9-44cb-96ce-bfe18a1c96a9] raised unexpected: DoesNotExist('Booking matching query does not exist.',)
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/celery/app/trace.py", line 374, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/celery/app/trace.py", line 629, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/harshil/Courses/SE/movie_recommender/functors/booker.py", line 9, in t_select
    try:
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 403, in get
    self.model._meta.object_name
booking_system.models.DoesNotExist: Booking matching query does not exist.

在打印booking.object.all((上,我得到了3个对象,这是我用来称为上述功能的对象。因此,不应该存在DoesNotExist错误。谁能帮我找出问题?

编辑:它仅在测试代码

时发生

您是否正在使用真实的芹菜过程?还是您的芹菜设置设置为渴望(如测试同步(?如果您使用的是真实的芹菜过程,那么您的对象很可能是在测试数据库中创建的,而芹菜的Django实例正在尝试访问真实的数据库。

尝试将设置设置为急切,看看它是否仍然具有相同的作用。

相关内容

  • 没有找到相关文章

最新更新