Skip to content

Commit 67e6324

Browse files
authored
Merge pull request #41 from octue/fix-empty-dict-error
Fix empty dict error
2 parents 3f88eff + 7eeb6c2 commit 67e6324

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"vscode": {
1212
"settings": {
1313
"austin.mode": "Wall time",
14+
"black-formatter.args": ["--line-length", "120"],
1415
"editor.defaultFormatter": "esbenp.prettier-vscode",
1516
"editor.formatOnSave": true,
1617
"esbonio.server.enabled": true,
@@ -29,7 +30,6 @@
2930
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
3031
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
3132
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
32-
// Line length to match black settings
3333
// Disabling specific messages:
3434
// - To find the details do: /usr/local/py-utils/bin/pylint --list-msgs
3535
// - Disable missing-module-docstring (C0114) because we don't document modules routinely, just their members

.devcontainer/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.8"
1+
version: '3.8'
22

33
# Developers:
44
#
@@ -11,9 +11,9 @@ services:
1111
context: ..
1212
dockerfile: .devcontainer/Dockerfile
1313
args:
14-
VARIANT: "3.9"
15-
INSTALL_NODE: "true"
16-
NODE_VERSION: "lts/*"
14+
VARIANT: '3.9'
15+
INSTALL_NODE: 'true'
16+
NODE_VERSION: 'lts/*'
1717

1818
environment:
1919
- DATABASE_URL=postgres://postgres_user:postgres_password@localhost/postgres_db
@@ -55,7 +55,7 @@ services:
5555
- postgres_data:/var/lib/postgresql
5656
restart: unless-stopped
5757
healthcheck:
58-
test: ["CMD-SHELL", "pg_isready -U postgres"]
58+
test: ['CMD-SHELL', 'pg_isready -U postgres']
5959
interval: 10s
6060
timeout: 5s
6161
retries: 5

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
workflow_dispatch:
88
inputs:
99
debug_enabled:
10-
description: "Enable tmate debug"
10+
description: 'Enable tmate debug'
1111
type: boolean
12-
default: "false"
12+
default: 'false'
1313

1414
jobs:
1515
check-semantic-version:
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
fail-fast: true
4444
matrix:
45-
python: ["3.9", "3.10"]
45+
python: ['3.9', '3.10']
4646
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest] for full coverage but this gets expensive quickly
4747
runs-on: ${{ matrix.os }}
4848

django_gcp/storage/fields.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,14 @@ def override_blobfield_value(self):
188188

189189
def pre_save(self, model_instance, add):
190190
"""Return field's value just before saving."""
191-
value = getattr(model_instance, self.attname)
191+
value = self._clean_blank_value(getattr(model_instance, self.attname))
192192

193193
existing_path = None if add else self._get_existing_path(model_instance)
194194

195195
# An escape hatch allowing you to set the path directly. This is dangerous and should only be done
196196
# explicitly for the purpose of data migration and manipulation. You should never allow an untrusted
197197
# client to set paths directly, because knowing the path of a pre-existing object allows you to assume
198198
# access to it. Tip: You can use django's override_settings context manager to set this temporarily.
199-
# Note that you'll have to execute any on_changed
200199
if getattr(
201200
settings,
202201
"GCP_STORAGE_OVERRIDE_BLOBFIELD_VALUE",
@@ -209,6 +208,7 @@ def pre_save(self, model_instance, add):
209208
)
210209
new_value = value
211210
else:
211+
212212
# There are six scenarios to deal with:
213213
adding_blank = add and value is None
214214
adding_valid = add and value is not None
@@ -448,6 +448,13 @@ def _check_on_change(self):
448448
]
449449
return []
450450

451+
@staticmethod
452+
def _clean_blank_value(value):
453+
"""Convert blanks values formulated as empty dicts {} to None"""
454+
if value is not None and len(value) == 0:
455+
value = None
456+
return value
457+
451458
def _get_allow_overwrite(self, add):
452459
"""Return a boolean determining if overwrite should be allowed for this operation"""
453460
mode_map = {

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.10.0"
3+
version = "0.10.1"
44
description = "Utilities to run Django on Google Cloud Platform"
55
authors = ["Tom Clark"]
66
license = "MIT"

tests/test_events_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import json
1111
from datetime import datetime, timezone
1212
from unittest.mock import patch
13+
from zoneinfo import ZoneInfo
1314
from django.test import TestCase
1415
from django_gcp.events.utils import decode_pubsub_message, get_event_url, make_pubsub_message
15-
from zoneinfo import ZoneInfo
1616

1717

1818
DEFAULT_SUBSCRIPTION = "projects/my-project/subscriptions/my-subscription"

0 commit comments

Comments
 (0)