depreciations: don't store job on scan on import (#89213)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-04-05 15:00:39 +02:00
parent 6bce31c255
commit 39fed220a5
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 8 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import pytest
from wcs.api_export_import import BundleDeclareJob, BundleImportJob, klass_to_slug
from wcs.applications import Application, ApplicationElement
from wcs.backoffice.deprecations import DeprecationsScan
from wcs.blocks import BlockDef
from wcs.carddef import CardDef
from wcs.categories import (
@ -25,6 +26,7 @@ from wcs.data_sources import NamedDataSource
from wcs.fields import BlockField, CommentField, ComputedField, PageField, StringField
from wcs.formdef import FormDef
from wcs.mail_templates import MailTemplate
from wcs.qommon.afterjobs import AfterJob
from wcs.sql import Equal
from wcs.wf.form import WorkflowFormFieldsFormDef
from wcs.workflows import Workflow, WorkflowBackofficeFieldsFormDef, WorkflowVariablesFieldsFormDef
@ -2120,6 +2122,7 @@ def test_export_import_workflow_options(pub):
def test_export_import_with_deprecated(pub):
AfterJob.wipe()
pub.load_site_options()
if not pub.site_options.has_section('options'):
pub.site_options.add_section('options')
@ -2145,6 +2148,9 @@ def test_export_import_with_deprecated(pub):
afterjob_url = resp.json['url']
resp = get_app(pub).put(sign_uri(afterjob_url))
assert resp.json['data']['status'] == 'failed'
assert AfterJob.count() == 1
job = AfterJob.select()[0]
assert not isinstance(job, DeprecationsScan)
blockdef = BlockDef()
blockdef.name = 'foo'

View File

@ -416,6 +416,7 @@ class DeprecationsScan(AfterJob):
)
def check_deprecated_elements_in_object(self, obj):
self.id = None # to avoid store of afterjob
if not get_publisher().has_site_option('forbid-new-python-expressions'):
# for perfs, don't check object if nothing is forbidden
return

View File

@ -87,7 +87,7 @@ class AfterJob(StorableObject):
def increment_count(self, amount=1):
self.current_count = (self.current_count or 0) + amount
# delay storage to avoid repeated writes on slow storage
if time.time() - self._last_store_time > 1:
if time.time() - self._last_store_time > 1 and self.id:
self.store()
def get_completion_status(self):