发生错误导致事务被归类为不可提交的事务(An error has occurred that has caused the transaction to be classified as an uncommittable transaction)
XACT_STATE()
可以有1,0,1个值。 当它为1时,可以执行任何操作,但是当它为-1时,只能执行读取或回滚。 在哪种情况下,交易被归类为不可提交的交易。这是msdn所说的。
当前请求具有活动用户事务,但是发生了导致事务被分类为不可提交事务的错误 。 请求无法提交事务或回滚到保存点; 它只能请求完全回滚事务。 在回滚事务之前,请求不能执行任何写操作。 请求只能在回滚事务之前执行读取操作。 回滚事务后,请求可以执行读取和写入操作,并可以开始新事务。
XACT_STATE()
can have 1, 0, -1 values. When it's 1, any action can be performed but when it's -1 only read or rollback can be performed. In which scenario a transaction is classified as uncommittable transaction.Here is what msdn says.
The current request has an active user transaction, but an error has occurred that has caused the transaction to be classified as an uncommittable transaction. The request cannot commit the transaction or roll back to a savepoint; it can only request a full rollback of the transaction. The request cannot perform any write operations until it rolls back the transaction. The request can only perform read operations until it rolls back the transaction. After the transaction has been rolled back, the request can perform both read and write operations and can begin a new transaction.
原文:https://stackoverflow.com/questions/35507558
最满意答案
Django Rest Framework在exception_handler中覆盖了Django Http404,因此您需要编写自己的异常。 例:
class NotFound(APIException): status_code = status.HTTP_404_NOT_FOUND default_detail = 'The resource was not found.' def __init__(self, detail=None): self.detail = detail or self.default_detail
Django Rest Framework overrides Django Http404 in exception_handler so you need to write your own exception. Example:
class NotFound(APIException): status_code = status.HTTP_404_NOT_FOUND default_detail = 'The resource was not found.' def __init__(self, detail=None): self.detail = detail or self.default_detail
相关问答
更多-
你正在寻找handler404 。 这是我的建议: 如果没有任何URL模式匹配,则创建应该调用的视图。 将handler404 = path.to.your.view添加到您的根URLconf。 这是如何完成的: project.views from django.http import JsonResponse def custom404(request): return JsonResponse({ 'status_code': 404, 'error': ' ...
-
好的,我的解决方法是使用django-filter 。 我的过滤器: class HolidayFilter(filters.FilterSet): """ This filter can be used to filter holidays by different values in API views or viewsets. See http://django-filter.readthedocs.io/en/1.1.0/guide/rest_framework.html ...
-
Django Rest Framework在exception_handler中覆盖了Django Http404,因此您需要编写自己的异常。 例: class NotFound(APIException): status_code = status.HTTP_404_NOT_FOUND default_detail = 'The resource was not found.' def __init__(self, detail=None): self.detai ...
-
问题出在以下代码中: def test_get_detail(self): ArtistTest._setup_add_record(self) response = self.client.get(url_3) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) 您无法调用ArtistTest._setup_add_record等实例方法。 您需要创建一个实例,调用像ArtistTest()._set ...
-
我应该使用ModelViewSet: class ListingViewSet(viewsets.ModelViewSet): ^^^^^ 感谢xordoquy在我打开的问题中指出了它。 I should have used the ModelViewSet: class ListingViewSet(viewsets.ModelViewSet): ^^^^^ Thanks to xo ...
-
from rest_framework.exceptions import NotFound NotFound类是从APIException扩展而来的。 APIException的默认状态代码是500 Internal Server Error ,而NotFound的默认状态代码是404 。 因此,根据我的说法,您正试图在纯django视图中抛出一个rest framework异常。 我在这里写了一个测试用例,来检查出现错误的几率。 猜猜试图提升rest framework异常的简单django视图不会被 ...
-
您的urls存在一些拼写错误。 您正在为
和 缺少名为group的正则表达式的 syntaxt。 以下将匹配上述所有404失败: urlpatterns = [ url(r'prices/?(?P [X]{1}[A-Z0-9]{3}:[A-Z0-9]{1}[A-Z09.-]{1,4})?/?(?P [0-9]{0,3})/?$', views.historyPrices, name='prices'), url(r'char ... -
使用Django REST Framework进行基于令牌的身份验证(Token based authentication with Django REST Framework)[2021-12-09]
使用Django休息框架进行令牌认证。 views.py from rest_framework.authentication import TokenAuthentication from rest_framework.permissions import IsAuthenticated class SampleView(APIView): authentication_classes = (TokenAuthentication,) permission_classes = (IsAu ... -
在Django REST Framework中未使用APIView解析URL(URL not resolved with APIView in Django REST Framework)[2022-04-07]
您的Url模式正则表达式错误..如果您仍想坚持您当前的网址格式,我建议您将您的请求网址从http://127.0.0.1:8000/api/song_search/?query=justin更改为http://127.0.0.1:8000/api/song_search/justin Your Url pattern Regular expression is wrong.. If you still want to stick to your current url pattern , I suggest ... -
实际上你的settings.py缺少xml解析器配置。 安装rest_framework_xml : pip install djangorestframework-xml 在settings.py中更新INSTALLED_APPS INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'djan ...