Skip to content

Commit 00e5e06

Browse files
committed
1 parent 1fa49a9 commit 00e5e06

File tree

6 files changed

+232
-11
lines changed

6 files changed

+232
-11
lines changed

.editorconfig

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{py,rst,ini}]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.{html,css,scss,json,yml}]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
22+
[Makefile]
23+
indent_style = tab

.github/workflows/ci.yml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-20.04
11+
12+
strategy:
13+
fail-fast: false
14+
15+
matrix:
16+
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
17+
django-version: ["1.11", "2.0", "2.2", "2.1", "3.0", "3.1","3.2", "4.0", "4.1",]
18+
es-dsl-version: ["6.4", "7.4"]
19+
es-version: ["7.13.4"]
20+
21+
exclude:
22+
- python-version: "2.7"
23+
django-version: "2.0"
24+
- python-version: "2.7"
25+
django-version: "2.1"
26+
- python-version: "2.7"
27+
django-version: "2.2"
28+
- python-version: "2.7"
29+
django-version: "3.0"
30+
- python-version: "2.7"
31+
django-version: "3.1"
32+
- python-version: "2.7"
33+
django-version: "3.2"
34+
- python-version: "2.7"
35+
django-version: "4.0"
36+
- python-version: "2.7"
37+
django-version: "4.1"
38+
39+
- python-version: "3.6"
40+
django-version: "4.0"
41+
- python-version: "3.6"
42+
django-version: "4.1"
43+
44+
- python-version: "3.7"
45+
django-version: "4.0"
46+
- python-version: "3.7"
47+
django-version: "4.1"
48+
49+
- python-version: "3.8"
50+
django-version: "1.11"
51+
- python-version: "3.8"
52+
django-version: "2.0"
53+
- python-version: "3.8"
54+
django-version: "2.1"
55+
56+
- python-version: "3.9"
57+
django-version: "1.11"
58+
- python-version: "3.9"
59+
django-version: "2.0"
60+
- python-version: "3.9"
61+
django-version: "2.1"
62+
63+
- python-version: "3.10"
64+
django-version: "1.11"
65+
- python-version: "3.10"
66+
django-version: "2.0"
67+
- python-version: "3.10"
68+
django-version: "2.1"
69+
- python-version: "3.10"
70+
django-version: "2.2"
71+
- python-version: "3.10"
72+
django-version: "3.0"
73+
- python-version: "3.10"
74+
django-version: "3.1"
75+
76+
- python-version: "3.11"
77+
django-version: "1.11"
78+
- python-version: "3.11"
79+
django-version: "2.0"
80+
- python-version: "3.11"
81+
django-version: "2.1"
82+
- python-version: "3.11"
83+
django-version: "2.2"
84+
- python-version: "3.11"
85+
django-version: "3.0"
86+
- python-version: "3.11"
87+
django-version: "3.1"
88+
- python-version: "3.11"
89+
django-version: "3.2"
90+
- python-version: "3.11"
91+
django-version: "4.0"
92+
93+
steps:
94+
- name: Install and Run Elasticsearch
95+
uses: elastic/elastic-github-actions/elasticsearch@master
96+
with:
97+
stack-version: ${{ matrix.es-version }}
98+
99+
- uses: actions/checkout@v2
100+
101+
- name: Install Python ${{ matrix.python-version }}
102+
uses: actions/setup-python@v2
103+
with:
104+
python-version: ${{ matrix.python-version }}
105+
106+
- name: Cache Pip Dependencies
107+
uses: actions/cache@v2
108+
with:
109+
path: ~/.cache/pip
110+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements_test.txt') }}
111+
restore-keys: |
112+
${{ runner.os }}-pip-
113+
114+
- name: Install Dependencies
115+
run: |
116+
python -m pip install --upgrade pip
117+
python -m pip install "Django==${{ matrix.django-version }}"
118+
python -m pip install "elasticsearch-dsl==${{ matrix.es-dsl-version }}"
119+
python -m pip install -r requirements_test.txt
120+
121+
- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and elasticsearch-dsl-py ${{ matrix.es-dsl-version }}
122+
run: |
123+
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-es${{ matrix.es-dsl-version }}" | tr -d .)
124+
python -m tox -e $TOX_ENV -- --elasticsearch
125+
python -m tox -e $TOX_ENV -- --elasticsearch --signal-processor celery
126+
127+
- name: Publish Coverage Report
128+
uses: codecov/codecov-action@v1

.gitignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
*.py[cod]
2+
__pycache__
3+
4+
# C extensions
5+
*.so
6+
7+
# Packages
8+
*.egg
9+
*.egg-info
10+
dist
11+
build
12+
eggs
13+
parts
14+
bin
15+
var
16+
sdist
17+
develop-eggs
18+
.installed.cfg
19+
lib
20+
lib64
21+
22+
# Installer logs
23+
pip-log.txt
24+
25+
# Unit test / coverage reports
26+
.coverage
27+
.tox
28+
nosetests.xml
29+
htmlcov
30+
31+
# Translations
32+
*.mo
33+
34+
# Mr Developer
35+
.mr.developer.cfg
36+
.project
37+
.pydevproject
38+
39+
# Pycharm/Intellij
40+
.idea
41+
42+
# Complexity
43+
output/*.html
44+
output/*/index.html
45+
46+
# Sphinx
47+
docs/_buildenv*
48+
49+
*.sqlite3
50+
_autofixture*

.readthedocs.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
3+
sphinx:
4+
configuration: docs/source/conf.py
5+
6+
formats: all
7+
8+
python:
9+
version: 3.8

README.md

-2
This file was deleted.

django_elasticsearch_dsl/signals.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ class CelerySignalProcessor(RealTimeSignalProcessor):
110110
Allows automatic updates on the index as delayed background tasks using
111111
Celery.
112112
113-
NB: We cannot process deletes as background tasks.
114-
By the time the Celery worker would pick up the delete job, the
115-
model instance would already deleted. We can get around this by
116-
setting Celery to use `pickle` and sending the object to the worker,
117-
but using `pickle` opens the application up to security concerns.
113+
Please note: We are unable to process deletions as background tasks.
114+
If we were to do so, the model instance might already be deleted by the time
115+
the Celery worker picks up the delete job. One workaround could be configuring
116+
Celery to use pickle and sending the object to the worker.
117+
However, employing pickle introduces potential security risks to the application.
118118
"""
119119

120120
def handle_save(self, sender, instance, **kwargs):
121121
"""Handle save with a Celery task.
122122
123-
Given an individual model instance, update the object in the index.
124-
Update the related objects either.
123+
Given an individual model instance, update the document in the index.
124+
Update the related objects as well.
125125
"""
126126
pk = instance.pk
127127
app_label = instance._meta.app_label
@@ -166,7 +166,7 @@ def prepare_registry_delete_related_task(self, instance):
166166
self.registry_delete_task.delay(doc_instance.__class__.__name__, bulk_data)
167167

168168
@shared_task()
169-
def registry_delete_task(doc_label, data):
169+
def registry_delete_task(doc_label, bulk_data):
170170
"""
171171
Handle the bulk delete data on the registry as a Celery task.
172172
The different implementations used are due to the difference between delete and update operations.
@@ -179,7 +179,20 @@ def registry_delete_task(doc_label, data):
179179

180180
def prepare_registry_delete_task(self, instance):
181181
"""
182-
Get the prepare did before database record deleted.
182+
Prepares the necessary data for a deletion task before a database record is deleted.
183+
184+
This function is called prior to the deletion of a database record. Its main role
185+
is to gather all relevant data related to the record that is about to be deleted
186+
and to queue a task that will handle the index update. The actual index update is
187+
performed by the `registry_delete_task`, which is triggered asynchronously.
188+
189+
Parameters:
190+
- instance (Model): The Django model instance that is about to be deleted.
191+
192+
The function iterates over documents related to the instance, collects necessary
193+
data, and prepares bulk data representing the delete action. This data is used
194+
to queue the `registry_delete_task`, which will handle updating the index to
195+
reflect the deletion.
183196
"""
184197
action = 'delete'
185198
for doc in registry._get_related_doc(instance):

0 commit comments

Comments
 (0)