coolair
V2EX  ›  问与答

请问下 Django REST framework 下如何避免返回 400 Response 时所有数据回滚?

  •  1
     
  •   coolair · Jun 11, 2021 · 650 views
    This topic created in 1803 days ago, the information mentioned may be changed or developed.
    在返回 status 为 400 时,会对整个 action 的数据库操作进行回滚,如果需要在 action 进行数据库操作,比如删除一个日志记录,那么就删除不了了,有什么办法解决吗?谢谢。

    ```
    @action(methods=['post'], detail=False, url_name='test')
    def test(self, request, pk=None):
    ...
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    ```
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   977 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:22 · PVG 04:22 · LAX 13:22 · JFK 16:22
    ♥ Do have faith in what you're doing.