Skip to content

Commit

Permalink
Raw base64 payload in FileField and ImageField fires `Deprecation…
Browse files Browse the repository at this point in the history
…Warning` 🏏
  • Loading branch information
Sibyx committed Feb 14, 2022
1 parent 2803e1e commit 6b561bb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## 0.21.0 : 15.12.2021
## 0.21.1 : 14.02.2022

- **Change**: Raw base64 payload in `FileField` and `ImageField` fires `DeprecationWarning`. Use Data URI instead.

## 0.21.0 : 03.02.2022

- **Feature**: Introduced `mapping`
- **Feature**: Override strategies using `field_type_strategy` and `field_strategy`
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ poetry run flake8 .

## Documentation

Documentation is places in `docs` directory and it's generated using
Documentation is placed in `docs` directory and it's generated using
[mkdocs-material](https://squidfunk.github.io/mkdocs-material/). You can build docs calling `poetry run mkdocs build`.
Docs will be in `sites` directory after build. Documentation is updated after every push to `origin/master` branch
using GitHub Actions.
10 changes: 8 additions & 2 deletions django_api_forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
import warnings
from base64 import b64decode
from enum import Enum
from io import BytesIO
Expand Down Expand Up @@ -230,8 +231,13 @@ def to_python(self, value: str) -> typing.Optional[File]:
if not value:
return None

if version >= "1.0.0":
if re.fullmatch(DATA_URI_PATTERN, value) is None:
if re.fullmatch(DATA_URI_PATTERN, value) is None:
warnings.warn(
"Raw base64 inside of FileField/ImageField is deprecated and will throw a validation error from "
"version >=1.0.0 Provide value as a Data URI.",
DeprecationWarning
)
if version >= "1.0.0":
raise ValidationError(self.error_messages["invalid_uri"], code="invalid_uri")

mime = None
Expand Down
2 changes: 1 addition & 1 deletion django_api_forms/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.21.0'
__version__ = '0.21.1'
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-api-forms"
version = "0.21.0"
version = "0.21.1"
description = "Declarative Django request validation"
authors = ["Jakub Dubec <[email protected]>", "Paul Brown <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def test_simple(self):
file_field = FileField()
django_file = file_field.clean(self._payload)

self.assertWarns(DeprecationWarning, lambda: file_field.clean(self._payload))
self.assertIsInstance(django_file, File)
self.assertEqual(django_file.size, 12412)

Expand Down Expand Up @@ -612,6 +613,7 @@ def test_simple(self):
image_field = ImageField()
django_image = image_field.clean(self._payload)

self.assertWarns(DeprecationWarning, lambda: image_field.clean(self._payload))
self.assertIsInstance(django_image, File)
self.assertEqual(django_image.size, 12412)
self.assertEqual(django_image.content_type, 'image/jpeg')
Expand Down

0 comments on commit 6b561bb

Please sign in to comment.