Skip to content
Snippets Groups Projects
Commit 53462cf3 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[backup] Add pk ordering back

parent 05dc15ad
No related branches found
No related tags found
1 merge request!211Issue 433
......@@ -158,6 +158,22 @@ class Command(BaseCommand):
arguments = copy.deepcopy(dump_arguments)
logger.info("Dumping data for `%s' -> `%s'", app, destfile)
if app in only:
app, model = only[app].split('.')
model = apps.get_model(app, model)
order = ('creation_date',)
# This will check and correct objects with weird creation
# dates so that the dump order is consistent
while True:
queryset = model.objects.order_by(*order)
err = _check(app, queryset)
if not err: break
arguments['primary_keys'] = \
','.join([str(k.id) for k in queryset])
arguments['output'] = destfile #new in Django-1.8.x
call_command('xdumpdata', only.get(app, app), **arguments)
......
......@@ -155,18 +155,17 @@ class Command(BaseCommand):
# ###################################################
queryset = objects.using(using)
if primary_keys:
# in case the user specifies PKs, respect order
for pk in [int(k) for k in primary_keys]:
if count_only:
yield queryset.count()
elif primary_keys:
for pk in primary_keys:
yield queryset.get(pk=pk)
elif count_only:
# ###################################################
# patch for BEAT ends here
# ###################################################
yield queryset.order_by().count()
else:
for obj in queryset.iterator():
yield obj
# ###################################################
# patch for BEAT ends here
# ###################################################
try:
self.stdout.ending = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment