Skip to content

Commit 0cc6c00

Browse files
committed
populate_history: support for default-date parameter
1 parent bee617d commit 0cc6c00

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Unreleased
55
----------
66

77
- Tests are no longer bundled in released wheels (gh-1478)
8+
- Added ``--default-date`` option to ``populate_history`` command (gh-688)
89

910
3.9.0 (2025-01-26)
1011
------------------

runtests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ def __getitem__(self, item):
4646
"default": {
4747
"ENGINE": "django.db.backends.postgresql",
4848
"NAME": "test",
49-
"USER": "debug",
50-
"PASSWORD": "debug",
49+
"USER": "postgres",
50+
"PASSWORD": "postgres",
5151
"HOST": "127.0.0.1",
5252
"PORT": 5432,
5353
},
5454
"other": {
5555
"ENGINE": "django.db.backends.postgresql",
5656
"NAME": "other",
57-
"USER": "debug",
58-
"PASSWORD": "debug",
57+
"USER": "postgres",
58+
"PASSWORD": "postgres",
5959
"HOST": "127.0.0.1",
6060
"PORT": 5432,
6161
},

simple_history/management/commands/populate_history.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def handle(self, *args, **options):
6767
if self.verbosity >= 1:
6868
self.stdout.write(self.COMMAND_HINT)
6969

70-
self._process(to_process, batch_size=options["batchsize"], default_date=options["default_date"])
70+
self._process(
71+
to_process,
72+
batch_size=options["batchsize"],
73+
default_date=options["default_date"],
74+
)
7175

7276
def _auto_models(self):
7377
to_process = set()
@@ -143,7 +147,9 @@ def _bulk_history_create(self, model, batch_size, default_date=None):
143147
# creating them. So we only keep batch_size worth of models in
144148
# historical_instances and clear them after we hit batch_size
145149
if index % batch_size == 0:
146-
history.bulk_history_create(instances, batch_size=batch_size, default_date=default_date)
150+
history.bulk_history_create(
151+
instances, batch_size=batch_size, default_date=default_date
152+
)
147153

148154
instances = []
149155

@@ -159,7 +165,9 @@ def _bulk_history_create(self, model, batch_size, default_date=None):
159165

160166
# create any we didn't get in the last loop
161167
if instances:
162-
history.bulk_history_create(instances, batch_size=batch_size, default_date=default_date)
168+
history.bulk_history_create(
169+
instances, batch_size=batch_size, default_date=default_date
170+
)
163171

164172
def _process(self, to_process, batch_size, default_date=None):
165173
for model, history_model in to_process:

simple_history/tests/tests/test_commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ def test_populate_with_default_date(self):
199199
Poll.objects.create(question="Will this populate?", pub_date=datetime.now())
200200
Poll.history.all().delete()
201201
management.call_command(
202-
self.command_name, auto=True, default_date=date, stdout=StringIO(), stderr=StringIO()
202+
self.command_name,
203+
auto=True,
204+
default_date=date,
205+
stdout=StringIO(),
206+
stderr=StringIO(),
203207
)
204208
self.assertEqual(Poll.history.all().count(), 1)
205209
self.assertEqual(Poll.history.all()[0].history_date, date)

simple_history/tests/tests/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,4 +656,3 @@ def test_update_change_reason_with_excluded_fields(self):
656656
update_change_reason(poll, "Test change reason.")
657657
most_recent = poll.history.order_by("-history_date").first()
658658
self.assertEqual(most_recent.history_change_reason, "Test change reason.")
659-

0 commit comments

Comments
 (0)