V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
coolair
V2EX  ›  问与答

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

  •  1
     
  •   coolair · Jun 11, 2021 · 597 views
    This topic created in 1783 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   ·   1471 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:54 · PVG 00:54 · LAX 09:54 · JFK 12:54
    ♥ Do have faith in what you're doing.