Skip to content

Commit

Permalink
Fix bug in auto redaction
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorodgerbrown committed Sep 26, 2023
1 parent cdfb7d0 commit f754ca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions anonymiser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def field_redaction_strategy(self, field: models.Field) -> FieldRedactionStrateg
def redact_queryset(
self,
queryset: models.QuerySet[models.Model],
auto_redact: bool = auto_redact,
auto_redact_override: bool | None = None,
**field_overrides: Any,
) -> int:
"""
Expand All @@ -210,7 +210,10 @@ def redact_queryset(
"""
redactions: dict[str, Any] = {}
if auto_redact:
auto = (
self.auto_redact if auto_redact_override is None else auto_redact_override
)
if auto:
redactions.update(self.auto_field_redactions())
redactions.update(self.custom_field_redactions)
redactions.update(field_overrides)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_redact_queryset_two(
assert user.uuid != user2.uuid

@pytest.mark.parametrize(
"auto_redact,location,biography",
"override,location,biography",
[
(True, 255 * "X", 400 * "X"),
(False, "London", "I am a test user"),
Expand All @@ -125,11 +125,11 @@ def test_redact_queryset__auto_redact(
self,
user: User,
user_redacter: UserRedacter,
auto_redact: bool,
override: bool,
location: str,
biography: str,
) -> None:
user_redacter.redact_queryset(User.objects.all(), auto_redact=auto_redact)
user_redacter.redact_queryset(User.objects.all(), auto_redact_override=override)
user.refresh_from_db()
# auto-redacted fields
assert user.location == location
Expand Down

0 comments on commit f754ca2

Please sign in to comment.