Skip to content

Commit 84aa48f

Browse files
committed
Merge remote-tracking branch 'origin/hotfix/2.6.8' into develop
2 parents 00d3af0 + 127bd73 commit 84aa48f

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pytest
1414
pytest-env
1515
python3-saml>=1.9,<1.10
1616
typing_extensions>=3.7.4
17-
moto[sqs]
17+
moto[sqs]<5.0
1818

1919
-e .
2020
-e git+https://github.com/superdesk/[email protected]#egg=superdesk-planning

superdesk/eve_backend.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from superdesk.errors import SuperdeskApiError
2727
from superdesk.notification import push_notification as _push_notification
2828
from superdesk.cache import cache
29+
from superdesk.utils import get_list_chunks
2930

3031

3132
SYSTEM_KEYS = set(
@@ -391,7 +392,8 @@ def delete_docs(self, endpoint_name, docs):
391392
except Exception:
392393
logger.exception("item can not be removed from elastic _id=%s" % (doc[config.ID_FIELD],))
393394
if len(removed_ids):
394-
backend.remove(endpoint_name, {config.ID_FIELD: {"$in": removed_ids}})
395+
for chunk in get_list_chunks(removed_ids):
396+
backend.remove(endpoint_name, {config.ID_FIELD: {"$in": chunk}})
395397
logger.info("Removed %d documents from %s.", len(removed_ids), endpoint_name)
396398
for doc in docs:
397399
self._push_resource_notification("deleted", endpoint_name, _id=str(doc["_id"]))

superdesk/text_checkers/ai/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class AIResource(Resource):
3333
"type": "dict",
3434
"required": True,
3535
"schema": {
36-
"guid": {"type": "string", "required": True},
36+
"guid": {"type": "string", "required": False},
3737
"abstract": {"type": "string", "required": False},
38-
"language": {"type": "string", "required": True},
39-
"headline": {"type": "string", "nullable": True},
38+
"language": {"type": "string", "required": False},
4039
"body_html": {"type": "string", "required": True},
40+
"headline": {"type": "string", "required": False},
41+
"slugline": {"type": "string", "required": False},
4142
},
4243
},
4344
"tags": {

superdesk/utils.py

+4
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,7 @@ def abort(status: int, message: str) -> None:
363363
for key, val in get_cors_headers():
364364
response.headers[key] = val
365365
flask.abort(response)
366+
367+
368+
def get_list_chunks(items, chunk_size=100):
369+
return [items[i : i + chunk_size] for i in range(0, len(items), chunk_size)]

tests/datalayer_tests.py

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
import superdesk
13+
1314
from bson import ObjectId
1415
from superdesk.tests import TestCase
1516
from superdesk.datalayer import SuperdeskJSONEncoder
@@ -65,3 +66,12 @@ def test_get_all_batch(self):
6566
assert item["_id"] == "test-{:04d}".format(counter)
6667
counter += 1
6768
assert counter == SIZE
69+
70+
def test_delete_chunks(self):
71+
items = []
72+
for i in range(5000): # must be larger than 1k
73+
items.append({"_id": ObjectId()})
74+
service = superdesk.get_resource_service("audit")
75+
service.create(items)
76+
service.delete({})
77+
assert 0 == service.find({}).count()

tests/utils_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ def test_allowed_container(self):
3434
self.assertNotIn("bar", container)
3535
allowed = [x for x in container]
3636
self.assertEqual(["foo"], allowed)
37+
38+
def test_list_chunks(self):
39+
items = [1, 2, 3, 4, 5]
40+
chunks = utils.get_list_chunks(items, 1)
41+
assert [[1], [2], [3], [4], [5]] == chunks
42+
chunks = utils.get_list_chunks(items, 2)
43+
assert [[1, 2], [3, 4], [5]] == chunks
44+
chunks = utils.get_list_chunks(items, 5)
45+
assert [[1, 2, 3, 4, 5]] == chunks
46+
chunks = utils.get_list_chunks(items, 10)
47+
assert [[1, 2, 3, 4, 5]] == chunks

0 commit comments

Comments
 (0)