Skip to content

Commit 282b6a5

Browse files
committed
Deprecate a ORM filter on tasks
Filtering tasks with `reserved_resources_record__resource` should be replaced by `reserved_resources_record__contains`. ref #8501
1 parent 40f3c71 commit 282b6a5

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate the use of the `reserved_resources_record__resource` in favor of `reserved_resources_record__contains`.
2+
Tentative removal release is pulpcore==3.15.

docs/plugins/plugin-writer/concepts/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ In 3.8 the following changes happen:
400400
2. The existing method signature ``def foo(a, b)`` is left in-tact.
401401
3. The ``foo`` method would have the a Python ``DeprecationWarning`` added to it such as::
402402

403-
from pulpcore.app.logging import deprecation_logger
404-
deprecation_logger.warn("foo() is deprecated and will be removed in pulpcore==3.9; use the_new_foo().")
403+
from pulpcore.app.loggers import deprecation_logger
404+
deprecation_logger.warning("foo() is deprecated and will be removed in pulpcore==3.9; use the_new_foo().")
405405

406406
4. A ``CHANGES/plugin_api/XXXX.deprecation`` changelog entry is created explaining how to port
407407
plugin code onto the new call interface.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.2.24 on 2021-06-15 12:11
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('core', '0064_repository_user_hidden'),
10+
('core', '0064_add_new_style_task_columns'),
11+
]
12+
13+
operations = [
14+
]

pulpcore/app/models/task.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pulpcore.constants import TASK_CHOICES, TASK_FINAL_STATES, TASK_STATES
2525
from pulpcore.exceptions import AdvisoryLockError, exception_to_dict
2626
from pulpcore.tasking.constants import TASKING_CONSTANTS
27+
from pulpcore.app.loggers import deprecation_logger
2728

2829
_logger = logging.getLogger(__name__)
2930

@@ -212,6 +213,19 @@ def _hash_to_u64(value):
212213
return int.from_bytes(_digest, byteorder="big", signed=True)
213214

214215

216+
class TaskManager(models.Manager):
217+
def filter(self, *args, **kwargs):
218+
value = kwargs.pop("reserved_resources_record__resource", None)
219+
if value is not None:
220+
deprecation_logger.warning(
221+
"Filtering tasks with 'reserved_resources_record__resource' is deprecated"
222+
" and may be removed as soon as pulpcore==3.15;"
223+
" use 'reserved_resources_record__contains' with a list of values instead."
224+
)
225+
kwargs["reserved_resources_record__contains"] = [value]
226+
return super().filter(*args, **kwargs)
227+
228+
215229
class Task(BaseModel, AutoDeleteObjPermsMixin, AutoAddObjPermsMixin):
216230
"""
217231
Represents a task
@@ -236,6 +250,8 @@ class Task(BaseModel, AutoDeleteObjPermsMixin, AutoAddObjPermsMixin):
236250
worker (models.ForeignKey): The worker that this task is in
237251
"""
238252

253+
objects = TaskManager()
254+
239255
state = models.TextField(choices=TASK_CHOICES)
240256
name = models.TextField()
241257
logging_cid = models.CharField(max_length=256, db_index=True, default="")

0 commit comments

Comments
 (0)