BTHLABS-53: Processing task fails for newly created saves
This commit is contained in:
parent
fb39818be3
commit
38d768a584
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
import django.db
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -21,15 +22,13 @@ class CreateSaveWorkflow(SaveWorkflow):
|
||||||
url: str,
|
url: str,
|
||||||
force_post_save: bool = False,
|
force_post_save: bool = False,
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
save = self.create(
|
with django.db.transaction.atomic():
|
||||||
account.pk,
|
save = self.create(
|
||||||
SaveIn(url=url),
|
account.pk,
|
||||||
)
|
SaveIn(url=url),
|
||||||
|
)
|
||||||
|
|
||||||
association = self.associate(account.pk, save)
|
association = self.associate(account.pk, save)
|
||||||
|
|
||||||
if save.last_processed_at is None:
|
|
||||||
processing_result = self.schedule_processing(save) # noqa: F841
|
|
||||||
|
|
||||||
response = redirect(reverse('ui.associations.browse'))
|
response = redirect(reverse('ui.associations.browse'))
|
||||||
if force_post_save is True or save.is_netloc_banned is True:
|
if force_post_save is True or save.is_netloc_banned is True:
|
||||||
|
@ -47,4 +46,7 @@ class CreateSaveWorkflow(SaveWorkflow):
|
||||||
response.headers['X-HotPocket-Testing-Save-PK'] = save.pk
|
response.headers['X-HotPocket-Testing-Save-PK'] = save.pk
|
||||||
response.headers['X-HotPocket-Testing-Association-PK'] = association.pk
|
response.headers['X-HotPocket-Testing-Association-PK'] = association.pk
|
||||||
|
|
||||||
|
if save.last_processed_at is None:
|
||||||
|
processing_result = self.schedule_processing(save) # noqa: F841
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
import http
|
import http
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import django.db
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
@ -21,19 +20,18 @@ def share_sheet(request: HttpRequest) -> HttpResponse:
|
||||||
LOGGER.debug('POST=`%s`', request.POST)
|
LOGGER.debug('POST=`%s`', request.POST)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with django.db.transaction.atomic():
|
assert request.user.is_anonymous is False, 'Login required'
|
||||||
assert request.user.is_anonymous is False, 'Login required'
|
assert 'text' in request.POST, 'Bad request: Missing `text`'
|
||||||
assert 'text' in request.POST, 'Bad request: Missing `text`'
|
|
||||||
|
|
||||||
url = request.POST['text'].split('\n')[0].strip()
|
url = request.POST['text'].split('\n')[0].strip()
|
||||||
assert url != '', 'Bad request: Empty `text`'
|
assert url != '', 'Bad request: Empty `text`'
|
||||||
|
|
||||||
return CreateSaveWorkflow().run(
|
return CreateSaveWorkflow().run(
|
||||||
request=request,
|
request=request,
|
||||||
account=request.user,
|
account=request.user,
|
||||||
url=url,
|
url=url,
|
||||||
force_post_save=True,
|
force_post_save=True,
|
||||||
)
|
)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
'Unhandled exception: %s',
|
'Unhandled exception: %s',
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
import http
|
import http
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import django.db
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
@ -19,19 +18,18 @@ def shortcut(request: HttpRequest) -> HttpResponse:
|
||||||
LOGGER.debug('GET=`%s`', request.GET)
|
LOGGER.debug('GET=`%s`', request.GET)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with django.db.transaction.atomic():
|
assert request.user.is_anonymous is False, 'Login required'
|
||||||
assert request.user.is_anonymous is False, 'Login required'
|
assert 'url' in request.GET, 'Bad request: Missing `url`'
|
||||||
assert 'url' in request.GET, 'Bad request: Missing `url`'
|
|
||||||
|
|
||||||
url = request.GET['url'].split('\n')[0].strip()
|
url = request.GET['url'].split('\n')[0].strip()
|
||||||
assert url != '', 'Bad request: Empty `url`'
|
assert url != '', 'Bad request: Empty `url`'
|
||||||
|
|
||||||
return CreateSaveWorkflow().run(
|
return CreateSaveWorkflow().run(
|
||||||
request=request,
|
request=request,
|
||||||
account=request.user,
|
account=request.user,
|
||||||
url=url,
|
url=url,
|
||||||
force_post_save=True,
|
force_post_save=True,
|
||||||
)
|
)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
'Unhandled exception: %s',
|
'Unhandled exception: %s',
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
import http
|
import http
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import django.db
|
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -24,12 +23,11 @@ class CreateView(AccountRequiredMixin, FormView):
|
||||||
form_class = CreateForm
|
form_class = CreateForm
|
||||||
|
|
||||||
def form_valid(self, form: CreateForm) -> HttpResponse:
|
def form_valid(self, form: CreateForm) -> HttpResponse:
|
||||||
with django.db.transaction.atomic():
|
return CreateSaveWorkflow().run(
|
||||||
return CreateSaveWorkflow().run(
|
request=self.request,
|
||||||
request=self.request,
|
account=self.request.user,
|
||||||
account=self.request.user,
|
url=form.cleaned_data['url'],
|
||||||
url=form.cleaned_data['url'],
|
)
|
||||||
)
|
|
||||||
|
|
||||||
def get_success_url(self) -> str:
|
def get_success_url(self) -> str:
|
||||||
return reverse('ui.associations.browse')
|
return reverse('ui.associations.browse')
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
extend-exclude =
|
extend-exclude =
|
||||||
hotpocket_backend/apps/*/migrations/*.py,
|
hotpocket_backend/apps/*/migrations/*.py,
|
||||||
node_modules/**/*.py,
|
node_modules/**/*.py,
|
||||||
skel/*.py
|
skel/*.py,
|
||||||
skel/*/*.py
|
skel/*/*.py,
|
||||||
|
playground.py
|
||||||
ignore = E131,W503,W504
|
ignore = E131,W503,W504
|
||||||
max-line-length = 119
|
max-line-length = 119
|
||||||
hang-closing = False
|
hang-closing = False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user