Skip to content

Commit ffbab9a

Browse files
committed
restore annotation that got replaced by a subquery, restore output in scrub_validation
1 parent 3e57aad commit ffbab9a

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Nothing
1313
-->
1414

15+
## [4.1.0] - 2025-03-04
16+
### Changed
17+
- Restore output in `scrub_validation` command
18+
- Move back to annotation, instead of Subquery for performance reasons
19+
1520
## [4.0.0] - 2025-02-19
1621
### Breaking
1722
- Removed support for Python 3.8

django_scrubber/management/commands/scrub_data.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.contrib.sessions.models import Session
88
from django.core.exceptions import FieldDoesNotExist
99
from django.core.management.base import BaseCommand, CommandError
10+
from django.db.models import F
1011
from django.db.utils import DataError, IntegrityError
1112

1213
from django_scrubber import settings_with_fallback
@@ -120,7 +121,9 @@ def _scrub_model(self, model_class, scrubber_apps_list, global_scrubbers):
120121
logger.info("Scrubbing %s with %s", model_class._meta.label, realized_scrubbers)
121122

122123
try:
123-
model_class.objects.update(**realized_scrubbers)
124+
model_class.objects.annotate(
125+
mod_pk=F("pk") % settings_with_fallback("SCRUBBER_ENTRIES_PER_PROVIDER"),
126+
).update(**realized_scrubbers)
124127
except IntegrityError as e:
125128
raise CommandError(
126129
f"Integrity error while scrubbing {model_class} ({e}); maybe increase SCRUBBER_ENTRIES_PER_PROVIDER?",

django_scrubber/management/commands/scrub_validation.py

+7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ def handle(self, *args, **options):
1515

1616
if len(non_scrubbed_field_list):
1717
for model_path, affected_field_list in non_scrubbed_field_list.items():
18+
self.stdout.write(f"Model {model_path!r}:")
19+
1820
found_models += 1
1921
for _field in affected_field_list:
22+
self.stdout.write(f"- {_field}")
2023
found_fields += 1
2124

25+
self.stdout.write("")
2226
if found_models > 0:
27+
self.stdout.write(f"{found_models} model(s) having {found_fields} unscrubbed field(s) detected.")
2328
sys.exit(1)
29+
30+
self.stdout.write("No unscrubbed fields detected. Yeah!")

django_scrubber/scrubbers.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import faker
77
from django.db import connections, router
88
from django.db.models import Field, Func, OuterRef, Subquery
9-
from django.db.models.functions import Cast, Mod
9+
from django.db.models.functions import Cast
1010
from django.db.models.functions import Concat as DjangoConcat
1111
from django.db.utils import IntegrityError
1212
from django.utils.translation import get_language, to_locale
@@ -200,10 +200,7 @@ def __call__(self, field):
200200
Subquery(
201201
FakeData.objects.filter(
202202
provider=self.provider_key,
203-
provider_offset=Mod(
204-
OuterRef("pk"),
205-
Subquery(FakeData.objects.provider_count(OuterRef("provider"))),
206-
),
203+
provider_offset=OuterRef("mod_pk"),
207204
).values("content")[:1],
208205
),
209206
field,

0 commit comments

Comments
 (0)