Skip to content

Commit f3af61f

Browse files
committed
fix: call to storage.client.remove_objects() corrected
Command "clean_orphaned_minio_files" improved by checking object name together with bucket name -> files with the same name won't yield false negative results Instances of client.put_object() have been updated for minio==7.2.20 Minimum version dependencies have been updated: * Python >=3.12 * minio==7.2.20 * Added support for Django 6.0 Reviewed-by: theriverman Refs: #70
1 parent 9cac4ac commit f3af61f

File tree

5 files changed

+23
-64
lines changed

5 files changed

+23
-64
lines changed

.github/workflows/django-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ['3.11', '3.12', '3.13', '3.14']
19-
django-version: ['4.2', '5.0', '5.1', '5.2']
18+
python-version: ['3.12', '3.13', '3.14']
19+
django-version: ['4.2', '5.2', '6.0']
2020

2121
steps:
2222
- uses: actions/checkout@v4

django_minio_backend/management/commands/clean_orphaned_minio_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def _clean_orphaned_files(self, storage: MinioBackend, db_files: set, dry_run: b
6363
object_name = obj.object_name
6464

6565
# Check if the object is referenced in the database
66-
if object_name not in db_files:
66+
if f"{bucket_name}/{object_name}" not in db_files:
6767
delete_objects.append(DeleteObject(object_name))
6868
self.stdout.write(f"Found orphaned file: {bucket_name}/{object_name}")
6969

7070
# Delete orphaned objects in bulk
7171
if delete_objects:
7272
if not dry_run:
73-
errors = storage.client.remove_objects(bucket_name, delete_objects)
73+
errors = storage.client.remove_objects(bucket_name=bucket_name, delete_object_list=delete_objects)
7474

7575
# Check for errors during deletion
7676
error_count = 0
@@ -160,7 +160,7 @@ def _collect_file_fields(self):
160160
if file_path := getattr(obj, field_name):
161161
bucket = file_path.storage.bucket
162162
file_path_str = str(file_path)
163-
db_files.add(file_path_str)
163+
db_files.add(f"{bucket}/{file_path_str}")
164164
db_files_by_model[model][field_name].append((obj.pk, f"{bucket}/{file_path_str}"))
165165
db_files.discard("")
166166

django_minio_backend/models.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,15 @@ def _save(self, file_path_name: str, content: InMemoryUploadedFile) -> str:
193193
data=content,
194194
length=-1,
195195
content_type=self._guess_content_type(file_path_name, content),
196-
headers=self._META_KWARGS.get('headers', None),
197-
user_metadata=self._META_KWARGS.get('user_metadata', None),
196+
metadata=self._META_KWARGS.get('metadata', None),
198197
sse=self._META_KWARGS.get('sse', None),
199198
progress=self._META_KWARGS.get('progress', None),
200199
part_size=self.__MINIO_MULTIPART_PART_SIZE,
201-
checksum=self._META_KWARGS.get('checksum', None),
202200
num_parallel_uploads=self._META_KWARGS.get('num_parallel_uploads', 3),
203201
tags=self._META_KWARGS.get('tags', None),
204202
retention=self._META_KWARGS.get('retention', None),
205203
legal_hold=self._META_KWARGS.get('legal_hold', False),
206-
region=self._META_KWARGS.get('region', None),
207-
extra_headers=self._META_KWARGS.get('extra_headers', None),
208-
extra_query_params=self._META_KWARGS.get('extra_query_params', None),
204+
write_offset=self._META_KWARGS.get('write_offset', None),
209205
)
210206
else:
211207
# Traditional upload - read entire file into memory
@@ -218,19 +214,15 @@ def _save(self, file_path_name: str, content: InMemoryUploadedFile) -> str:
218214
data=content_bytes,
219215
length=content_length,
220216
content_type=self._guess_content_type(file_path_name, content),
221-
headers=self._META_KWARGS.get('headers', None),
222-
user_metadata=self._META_KWARGS.get('user_metadata', None),
217+
metadata=self._META_KWARGS.get('metadata', None),
223218
sse=self._META_KWARGS.get('sse', None),
224219
progress=self._META_KWARGS.get('progress', None),
225220
part_size=0,
226-
checksum=self._META_KWARGS.get('checksum', None),
227221
num_parallel_uploads=self._META_KWARGS.get('num_parallel_uploads', 3),
228222
tags=self._META_KWARGS.get('tags', None),
229223
retention=self._META_KWARGS.get('retention', None),
230224
legal_hold=self._META_KWARGS.get('legal_hold', False),
231-
region=self._META_KWARGS.get('region', None),
232-
extra_headers=self._META_KWARGS.get('extra_headers', None),
233-
extra_query_params=self._META_KWARGS.get('extra_query_params', None),
225+
write_offset=self._META_KWARGS.get('write_offset', None),
234226
)
235227
return file_path.as_posix()
236228

@@ -243,7 +235,7 @@ def _get_cache_key(self, name: str) -> str:
243235
# Try to get the ETag from the object stats
244236
obj = self.stat(name)
245237
etag = obj.etag if hasattr(obj, 'etag') else ''
246-
except (AttributeError, Exception) as e:
238+
except (AttributeError, Exception):
247239
etag = ''
248240

249241
# Create a unique key using the bucket name, file name, and ETag

pyproject.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@ authors = [
77
]
88
readme = "README.md"
99
license = { text = "MIT" }
10-
requires-python = ">=3.11"
10+
requires-python = ">=3.12"
1111
dependencies = [
1212
"Django>=4.2",
13-
"minio==7.2.19",
14-
"Pillow>=10.0.0", # Required for example application
13+
"minio==7.2.20",
14+
"Pillow>=10.0.0", # Required for example application
1515
]
1616
classifiers = [
1717
"Environment :: Web Environment",
1818
"Framework :: Django",
1919
"Framework :: Django :: 4.2",
20-
"Framework :: Django :: 5.0",
21-
"Framework :: Django :: 5.1",
2220
"Framework :: Django :: 5.2",
21+
"Framework :: Django :: 6.0",
2322
"Intended Audience :: Developers",
2423
"License :: OSI Approved :: MIT License",
2524
"Operating System :: OS Independent",
2625
"Programming Language :: Python",
27-
"Programming Language :: Python :: 3.11",
2826
"Programming Language :: Python :: 3.12",
2927
"Programming Language :: Python :: 3.13",
3028
"Programming Language :: Python :: 3.14",

0 commit comments

Comments
 (0)