Skip to content

Commit aba39e3

Browse files
committed
Merge remote-tracking branch 'upstream/master' into devel
2 parents 9b97734 + ad508fe commit aba39e3

File tree

9 files changed

+119
-54
lines changed

9 files changed

+119
-54
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.3.0
2+
current_version = 2.3.1
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?P<releaselevel>[a-z]+)?

.github/workflows/test.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
17-
django: [ 22, 32, 40 ]
18-
exclude:
19-
- python-version: "3.10"
20-
django: 22
21-
- python-version: 3.7
22-
django: 40
16+
python-version: [ 3.8, 3.9, "3.10" ]
17+
django: [ 32, 40 ]
18+
2319
services:
2420
postgres:
2521
image: postgres

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.32.0
3+
rev: v2.32.1
44
hooks:
55
- id: pyupgrade
66
args: ["--py36-plus"]

Changelog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
Change history
55
================
66

7+
.. _version-2.4.0:
8+
9+
2.4.0
10+
=====
11+
:release-date: NA
12+
:release-by: NA
13+
14+
- Fix [#315](https://github.com/celery/django-celery-results/issues/315) Save args, kwargs and other extended props only when result_extended config is set to True
15+
16+
17+
.. _version-2.3.1:
18+
19+
2.3.1
20+
=====
21+
:release-date: 2022-04-17 12:50 P.M. UTC+6:00
22+
:release-by: Asif Saif Uddin
23+
24+
- Remove hard dependency on psycopg2.
25+
- Fix #296 Stop producing a universal wheel, python 2 is unspported.
26+
- fix: The description content type for setuptools needs to be rst to markdown.
27+
28+
729
.. _version-2.3.0:
830

931
2.3.0

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
|build-status| |coverage| |license| |wheel| |pyversion| |pyimp|
66

7-
:Version: 2.3.0
7+
:Version: 2.3.1
88
:Web: http://django-celery-results.readthedocs.io/
99
:Download: http://pypi.python.org/pypi/django-celery-results
1010
:Source: http://github.com/celery/django-celery-results
@@ -114,7 +114,7 @@ max_length of **191** seems to work for MySQL.
114114
:target: http://pypi.python.org/pypi/django-celery-results/
115115

116116
django-celery-results as part of the Tidelift Subscription
117-
-----------------
117+
----------------------------------------------------------
118118

119119
The maintainers of django-celery-results and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/pypi-django-celery-results?utm_source=pypi-django-celery-results&utm_medium=referral&utm_campaign=readme&utm_term=repo)
120120

django_celery_results/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import django
1010

11-
__version__ = '2.3.0'
11+
__version__ = '2.3.1'
1212
__author__ = 'Asif Saif Uddin, Ask Solem'
1313
__contact__ = 'auvipy@gmai.com, ask@celeryproject.org'
1414
__homepage__ = 'https://github.com/celery/django-celery-results'

django_celery_results/backends/database.py

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,51 @@ def exception_safe_to_retry(self, exc):
5454
return True
5555
return False
5656

57+
def _get_extended_properties(self, request, traceback):
58+
extended_props = {
59+
'periodic_task_name': None,
60+
'task_args': None,
61+
'task_kwargs': None,
62+
'task_name': None,
63+
'traceback': None,
64+
'worker': None,
65+
}
66+
if request and self.app.conf.find_value_for_key('extended', 'result'):
67+
68+
if getattr(request, 'argsrepr', None) is not None:
69+
# task protocol 2
70+
task_args = request.argsrepr
71+
else:
72+
# task protocol 1
73+
task_args = getattr(request, 'args', None)
74+
75+
if getattr(request, 'kwargsrepr', None) is not None:
76+
# task protocol 2
77+
task_kwargs = request.kwargsrepr
78+
else:
79+
# task protocol 1
80+
task_kwargs = getattr(request, 'kwargs', None)
81+
82+
# Encode input arguments
83+
if task_args is not None:
84+
_, _, task_args = self.encode_content(task_args)
85+
86+
if task_kwargs is not None:
87+
_, _, task_kwargs = self.encode_content(task_kwargs)
88+
89+
properties = getattr(request, 'properties', {}) or {}
90+
periodic_task_name = properties.get('periodic_task_name', None)
91+
extended_props.update({
92+
'periodic_task_name': periodic_task_name,
93+
'task_args': task_args,
94+
'task_kwargs': task_kwargs,
95+
'task_name': getattr(request, 'task', None),
96+
'traceback': traceback,
97+
'worker': getattr(request, 'hostname', None),
98+
})
99+
100+
return extended_props
101+
57102
def _store_result(
58103
self,
59104
task_id,
@@ -69,48 +114,22 @@ def _store_result(
69114
{'children': self.current_task_children(request)}
70115
)
71116

72-
task_name = getattr(request, 'task', None)
73-
properties = getattr(request, 'properties', {}) or {}
74-
periodic_task_name = properties.get('periodic_task_name', None)
75-
worker = getattr(request, 'hostname', None)
76-
77-
# Get input arguments
78-
if getattr(request, 'argsrepr', None) is not None:
79-
# task protocol 2
80-
task_args = request.argsrepr
81-
else:
82-
# task protocol 1
83-
task_args = getattr(request, 'args', None)
84-
85-
if getattr(request, 'kwargsrepr', None) is not None:
86-
# task protocol 2
87-
task_kwargs = request.kwargsrepr
88-
else:
89-
# task protocol 1
90-
task_kwargs = getattr(request, 'kwargs', None)
91-
92-
# Encode input arguments
93-
if task_args is not None:
94-
_, _, task_args = self.encode_content(task_args)
95-
96-
if task_kwargs is not None:
97-
_, _, task_kwargs = self.encode_content(task_kwargs)
98-
99-
self.TaskModel._default_manager.store_result(
100-
content_type,
101-
content_encoding,
102-
task_id,
103-
result,
104-
status,
105-
traceback=traceback,
106-
meta=meta,
107-
periodic_task_name=periodic_task_name,
108-
task_name=task_name,
109-
task_args=task_args,
110-
task_kwargs=task_kwargs,
111-
worker=worker,
112-
using=using,
117+
task_props = {
118+
'content_encoding': content_encoding,
119+
'content_type': content_type,
120+
'meta': meta,
121+
'result': result,
122+
'status': status,
123+
'task_id': task_id,
124+
'traceback': traceback,
125+
'using': using,
126+
}
127+
128+
task_props.update(
129+
self._get_extended_properties(request, traceback)
113130
)
131+
132+
self.TaskModel._default_manager.store_result(**task_props)
114133
return result
115134

116135
def _get_task_meta_for(self, task_id):

docs/includes/introduction.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:Version: 2.3.0
1+
:Version: 2.3.1
22
:Web: http://django-celery-results.readthedocs.io/
33
:Download: http://pypi.python.org/pypi/django-celery-results
44
:Source: http://github.com/celery/django-celery-results

t/unit/backends/test_database.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def setup_backend(self):
3131
self.app.conf.result_serializer = 'json'
3232
self.app.conf.result_backend = (
3333
'django_celery_results.backends:DatabaseBackend')
34+
self.app.conf.result_extended = True
3435
self.b = DatabaseBackend(app=self.app)
3536

3637
def _create_request(self, task_id, name, args, kwargs,
@@ -859,3 +860,30 @@ def test_groupresult_save_restore_nested(self):
859860
restored_group = self.b.restore_group(group_id=group_id)
860861

861862
assert restored_group == group
863+
864+
def test_backend_result_extended_is_false(self):
865+
self.app.conf.result_extended = False
866+
self.b = DatabaseBackend(app=self.app)
867+
tid2 = uuid()
868+
request = self._create_request(
869+
task_id=tid2,
870+
name='my_task',
871+
args=['a', 1, True],
872+
kwargs={'c': 6, 'd': 'e', 'f': False},
873+
)
874+
result = 'foo'
875+
876+
self.b.mark_as_done(tid2, result, request=request)
877+
878+
mindb = self.b.get_task_meta(tid2)
879+
880+
# check meta data
881+
assert mindb.get('result') == 'foo'
882+
assert mindb.get('task_name') is None
883+
assert mindb.get('task_args') is None
884+
assert mindb.get('task_kwargs') is None
885+
886+
# check task_result object
887+
tr = TaskResult.objects.get(task_id=tid2)
888+
assert tr.task_args is None
889+
assert tr.task_kwargs is None

0 commit comments

Comments
 (0)