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

[backup] Add pk ordering back

parent f7f9d0bd
No related branches found
No related tags found
No related merge requests found
...@@ -158,6 +158,22 @@ class Command(BaseCommand): ...@@ -158,6 +158,22 @@ class Command(BaseCommand):
arguments = copy.deepcopy(dump_arguments) arguments = copy.deepcopy(dump_arguments)
logger.info("Dumping data for `%s' -> `%s'", app, destfile) 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 arguments['output'] = destfile #new in Django-1.8.x
call_command('xdumpdata', only.get(app, app), **arguments) call_command('xdumpdata', only.get(app, app), **arguments)
......
...@@ -155,18 +155,17 @@ class Command(BaseCommand): ...@@ -155,18 +155,17 @@ class Command(BaseCommand):
# ################################################### # ###################################################
queryset = objects.using(using) queryset = objects.using(using)
if primary_keys: if count_only:
# in case the user specifies PKs, respect order yield queryset.count()
for pk in [int(k) for k in primary_keys]: elif primary_keys:
for pk in primary_keys:
yield queryset.get(pk=pk) yield queryset.get(pk=pk)
elif count_only:
# ###################################################
# patch for BEAT ends here
# ###################################################
yield queryset.order_by().count()
else: else:
for obj in queryset.iterator(): for obj in queryset.iterator():
yield obj yield obj
# ###################################################
# patch for BEAT ends here
# ###################################################
try: try:
self.stdout.ending = None 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