From ed668a134899b1b8d1a427edb77194cf410cde4f Mon Sep 17 00:00:00 2001 From: fleaz Date: Mon, 30 Mar 2020 21:58:43 +0200 Subject: [PATCH] autosort: Fix bug where transactions get sorted even with --dry-run --- autosort.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autosort.py b/autosort.py index 74563b9..1b3347d 100644 --- a/autosort.py +++ b/autosort.py @@ -27,7 +27,7 @@ def command(profile, dry_run, verbose): unsorted = session.query(Transaction).filter(Transaction.category_id == None).all() print("Found {} unsorted transcations".format(len(unsorted))) - matched = 0 + new = [] for t in unsorted: cat_name = apply_rules(t, rules) @@ -39,13 +39,13 @@ def command(profile, dry_run, verbose): cat_id = session.query(Category).filter(Category.name == cat_name).first() if not cat_id: cat_id = add_category(cat_name, profile, session) - matched += 1 t.category_id = cat_id - session.add(t) + new.append(t) print_verbose(verbose, "-" * 90) - print(f"Automatically matched {matched} transactions") + print(f"Automatically matched {len(new)} transactions") if not dry_run: + session.bulk_save_object(new) session.commit()