Pin django-stdimage to sub 6.0.0 (#3273)

* Pin django-stdimage to sub 6.0.0

- 6.0.0 breaks model serialization for background worker task
- NFI why it does this

* Fix requirements file

* remove windows deps. and append requirements

* Add unit tests for encoding and offloading tasks

Co-authored-by: Matthias <code@mjmair.com>
This commit is contained in:
Oliver 2022-06-29 20:47:06 +10:00 committed by GitHub
parent 73445b4b79
commit efbef2dc90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 5 deletions

View File

@ -61,7 +61,7 @@ def raise_warning(msg):
warnings.warn(msg)
def offload_task(taskname, *args, force_sync=False, **kwargs):
def offload_task(taskname, *args, force_async=False, force_sync=False, **kwargs):
"""Create an AsyncTask if workers are running. This is different to a 'scheduled' task, in that it only runs once!
If workers are not running or force_sync flag
@ -79,7 +79,7 @@ def offload_task(taskname, *args, force_sync=False, **kwargs):
except (OperationalError, ProgrammingError): # pragma: no cover
raise_warning(f"Could not offload task '{taskname}' - database not ready")
if is_worker_running() and not force_sync: # pragma: no cover
if force_async or (is_worker_running() and not force_sync):
# Running as asynchronous task
try:
task = AsyncTask(taskname, *args, **kwargs)

View File

@ -20,9 +20,11 @@ from djmoney.money import Money
import InvenTree.tasks
from common.models import InvenTreeSetting
from common.settings import currency_codes
from stock.models import StockLocation
from part.models import Part, PartCategory
from stock.models import StockItem, StockLocation
from . import config, helpers, ready, status, version
from .tasks import offload_task
from .validators import validate_overage, validate_part_name
@ -618,3 +620,48 @@ class TestInstanceName(helpers.InvenTreeTestCase):
# The site should also be changed
site_obj = Site.objects.all().order_by('id').first()
self.assertEqual(site_obj.domain, 'http://127.1.2.3')
class TestOffloadTask(helpers.InvenTreeTestCase):
"""Tests for offloading tasks to the background worker"""
fixtures = [
'category',
'part',
'location',
'stock',
]
def test_offload_tasks(self):
"""Test that we can offload various tasks to the background worker thread.
This set of tests also ensures that various types of objects
can be encoded by the django-q serialization layer!
Note that as the background worker is not actually running for the tests,
the call to 'offload_task' won't really *do* anything!
However, it serves as a validation that object serialization works!
Ref: https://github.com/inventree/InvenTree/pull/3273
"""
offload_task(
'dummy_tasks.parts',
part=Part.objects.get(pk=1),
cat=PartCategory.objects.get(pk=1),
force_async=True
)
offload_task(
'dummy_tasks.stock',
item=StockItem.objects.get(pk=1),
loc=StockLocation.objects.get(pk=1),
force_async=True
)
offload_task(
'dummy_task.numbers',
1, 2, 3, 4, 5,
force_async=True
)

View File

@ -18,7 +18,7 @@ django-redis>=5.0.0 # Redis integration
django-q # Background task scheduling
django-sql-utils # Advanced query annotation / aggregation
django-sslserver # Secure HTTP development server
django-stdimage # Advanced ImageField management
django-stdimage<6.0.0 # Advanced ImageField management # FIXED 2022-06-29 6.0.0 breaks serialization for django-q
django-user-sessions # user sessions in DB
django-weasyprint # django weasyprint integration
djangorestframework # DRF framework

View File

@ -107,7 +107,7 @@ django-sql-utils==0.6.1
# via -r requirements.in
django-sslserver==0.22
# via -r requirements.in
django-stdimage==6.0.1
django-stdimage==5.3.0
# via -r requirements.in
django-user-sessions==1.7.1
# via -r requirements.in