Skip to content

Commit

Permalink
Fix bug with naive datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorodgerbrown committed Oct 2, 2023
1 parent a45225f commit 0dc01fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions anonymiser/redacters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import datetime
from typing import Any, Callable

from django.db import models
Expand All @@ -16,12 +17,12 @@ def default_redact_textfield(field: models.TextField) -> str:
return "X" * 400


def default_redact_datefield(field: models.DateField) -> str:
return timezone.now().date().isoformat()
def default_redact_datefield(field: models.DateField) -> datetime.date:
return timezone.now().date()


def default_redact_datetimefield(field: models.DateTimeField) -> str:
return timezone.now().isoformat()
def default_redact_datetimefield(field: models.DateTimeField) -> datetime.datetime:
return timezone.now()


def default_redact_jsonfield(field: models.JSONField) -> dict[str, Any]:
Expand All @@ -40,10 +41,10 @@ def get_default_field_redacter(
return default_redact_charfield
if isinstance(field, models.TextField):
return default_redact_textfield
if isinstance(field, models.DateField):
return default_redact_datefield
if isinstance(field, models.DateTimeField):
return default_redact_datetimefield
if isinstance(field, models.DateField):
return default_redact_datefield
if isinstance(field, models.JSONField):
return default_redact_jsonfield
if isinstance(field, models.UUIDField):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_auto_redact(
assert user_redacter.get_auto_redaction_values() == {
"char_field": 255 * "X",
"text_field": 400 * "X",
"date_field": "2021-01-01",
"date_field": freezegun.api.FakeDate(2021, 1, 1),
}


Expand Down

0 comments on commit 0dc01fe

Please sign in to comment.