Skip to content

Commit 99d1932

Browse files
authored
Merge pull request #36 from octue/improve-docs
FIX: Logger getting incorrect path
2 parents fdcd88a + acd3b39 commit 99d1932

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ repos:
4343
- id: check-branch-name
4444
args:
4545
- '^main$'
46-
- '^devops/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
47-
- '^test/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
48-
- '^doc/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
49-
- '^feature/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
50-
- '^fix/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
51-
- '^refactor/([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
46+
- '^([a-z][a-z0-9#]*)(-[a-z0-9#]+)*$'
5247

5348
- repo: https://github.com/pre-commit/mirrors-prettier
5449
rev: 'v2.2.1'

django_gcp/storage/fields.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323

2424
DEFAULT_OVERWRITE_MODE = "never"
2525

26+
OVERWRITE_MODES = [
27+
"never",
28+
"update",
29+
"update-versioned",
30+
"add",
31+
"add-versioned",
32+
"add-update",
33+
"add-update-versioned",
34+
]
35+
2636
DEFAULT_OVERRIDE_BLOBFIELD_VALUE = False
2737

2838

@@ -31,28 +41,23 @@ class BlobField(models.JSONField):
3141
3242
Features such as metadata fetching/synchronisation and direct uploads are enabled.
3343
34-
ObjectField allows storage classes to be declared in settings. This enables:
44+
BlobField allows storage classes to be declared in settings. This enables:
3545
- storages to be switched without database migrations (supporting integration
3646
and release preview type workflows plus cloud migration)
37-
- eaiser way of using different buckets for different ObjectFields without
47+
- eaiser way of using different buckets for different BlobFields without
3848
defining a Storage class for each bucket
3949
40-
ObjectField is built on JSONField to allow more complex information to be stored
50+
BlobField is built on JSONField to allow more complex information to be stored
4151
and queried. Examples might include:
4252
- cached object generation or metageneration,
4353
- cached object metadata, or
4454
- status of direct uploads
4555
46-
ObjectField does not inherit directly from FileField to avoid the burden of strict
56+
BlobField does not inherit directly from FileField to avoid the burden of strict
4757
compatibility with legacy or irrelevant-to-cloud-storage behaviour (like django
4858
admin overriding formfields or coping with edge cases around name and path handling).
4959
We do this to support a clear and maintainable implementation.
5060
51-
ObjectField can read FileField entries: since FileField stores the path as a string,
52-
that's valid JSON so can be accepted by ObjectField, greatly simplifying migration.
53-
Once a model instance has been updated, its entry will be a JSON object and so will
54-
no longer be trivially reversible to a valid FileField entry without a custom migration.
55-
5661
:param ingress_to: A string defining the path within the bucket to which direct uploads
5762
will be ingressed, if temporary_ingress=True. These uploaded files will be moved to their
5863
ultimate path in the store on save of the model.
@@ -61,15 +66,26 @@ class BlobField(models.JSONField):
6166
specific mimetype. No validation is done at the field level that objects actually are of this
6267
type (because the python mimetypes module doesn't accept wildcard mimetypes and we don't want to
6368
go on a wild goose chase just for this small feature).
69+
6470
:param get_destination_path: A callable to determine the destination path of the blob.
6571
The blob should already have been successfully uploaded to the temporary location
6672
in GCP prior to creation of this model instance. This function is then called in the
6773
pre_save stage of the new model instance, so it has access to all the model fields in
6874
order to construct the destination filename. Note this EXCLUDES the id, if the model has an
6975
autoincrementing ID field that gets created on save, because that can't be known prior to
7076
the save.
77+
7178
:param max_size_bytes: The maximum size in bytes of files that can be uploaded.
7279
80+
:overwrite_mode: One of `OVERWRITE_MODES` determining the circumstances under which overwrite
81+
is allowed. overwrite mode behaves as follows:
82+
- never: Never allows overwrite
83+
- update: Only when updating an object
84+
- update-versioned: Only when updating an object and the bucket has object versioning
85+
- add: Only when adding an object (we're not sure why you'd want this, here for completeness)
86+
- add-versioned: Only when adding an object to a versioned bucket (again, for completeness)
87+
- add-update: Always allow (ie when adding or updating an object)
88+
- add-update-versioned: When adding or updating an object to a versioned bucket
7389
"""
7490

7591
description = _("A GCP Cloud Storage object")
@@ -170,9 +186,9 @@ def pre_save(self, model_instance, add):
170186
# access to it. Tip: You can use django's override_settings context manager to set this temporarily.
171187
if getattr(settings, "GCP_STORAGE_OVERRIDE_BLOBFIELD_VALUE", DEFAULT_OVERRIDE_BLOBFIELD_VALUE):
172188
logger.warning(
173-
"Overriding %s value with path %s",
189+
"Overriding %s value to %s",
174190
self.__class__.__name__,
175-
getattr(value, "path", None),
191+
value,
176192
)
177193
new_value = value
178194
else:
@@ -358,22 +374,13 @@ def _check_ingress_to(self):
358374
return []
359375

360376
def _check_overwrite_mode(self):
361-
allowable_modes = [
362-
"never",
363-
"update",
364-
"update-versioned",
365-
"add",
366-
"add-versioned",
367-
"add-update",
368-
"add-update-versioned",
369-
]
370-
if self.overwrite_mode not in allowable_modes:
377+
if self.overwrite_mode not in OVERWRITE_MODES:
371378
return [
372379
checks.Error(
373380
"{self.__class__.__name__}'s 'overwrite_mode' is invalid",
374381
obj=self,
375382
id="fields.E202",
376-
hint=f"Try one of: {allowable_modes}",
383+
hint=f"Try one of: {OVERWRITE_MODES}",
377384
)
378385
]
379386
return []

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-gcp"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
description = "Utilities to run Django on Google Cloud Platform"
55
authors = ["Tom Clark"]
66
license = "MIT"

0 commit comments

Comments
 (0)