From fb13941756a6f1338baf83d6c6ea0acfc666f91b Mon Sep 17 00:00:00 2001 From: Jan Bertram Date: Thu, 16 Nov 2023 11:15:10 +0100 Subject: [PATCH] fixes bug: crash by marking work as mastered twice, updates README with more known bugs --- README.md | 6 ++++-- rep_cli.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ce10295..aafb966 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ At the moment, an alpha version is undertaken, with these features: - Works are shown sorted by composer and opus/work_directory-number (`s`, `smo`) or by composer and collection (`sm`) - Remove work or movement from being mastered for active user (`r number_of_work` or `r number_of_work number_of_movement`) - Remove user (`delete_my_user_record_including_all_mastered_works`) -- (planned) Fix known bugs +- Fix bug: double marking crashes the program _(planned) Release piano_repertoire_cli V 0.0.1 alpha (learn about versioning before)_ @@ -44,4 +44,6 @@ _(planned) Port funtionality to a kivy-GUI_ ## Known Bugs -- Marking a piece as mastered the second time, the database won’t insert the entry and the program will crash \ No newline at end of file +- User numbers are allowed to set without a user being present, with marking works as mastered leading to crash the program +- Trying to mark works as mastered that are not present crashes the program +- Providing alphabetic chars where numbers are expected crashes the program \ No newline at end of file diff --git a/rep_cli.py b/rep_cli.py index 4134bfa..28d7010 100644 --- a/rep_cli.py +++ b/rep_cli.py @@ -218,20 +218,26 @@ class Session: work = work_under_id(work_id, self.db_agent) if len(arguments) > 1: # in case there is a movement number given mov_number = int(arguments[1]) - sql_command = f''' - INSERT INTO is_able_to_play (work_id, mov_id, pianist_id) - VALUES ({work_id}, {mov_number}, {self.user}) - ''' - self.db_agent.execute(sql_command) - resultstring += f'{work.pretty_mov(mov_number)}\n' - else: # mark all movements of the work as mastered - for mov_number in work.values['movements'].keys(): + if self.movement_is_mastered(work_id, mov_number): + resultstring += f'Already marked as mastered: {work.pretty_mov(mov_number)}\n' + else: sql_command = f''' INSERT INTO is_able_to_play (work_id, mov_id, pianist_id) VALUES ({work_id}, {mov_number}, {self.user}) ''' self.db_agent.execute(sql_command) resultstring += f'{work.pretty_mov(mov_number)}\n' + else: # mark all movements of the work as mastered + for mov_number in work.values['movements'].keys(): + if self.movement_is_mastered(work_id, mov_number): + resultstring += f'Already marked as mastered: {work.pretty_mov(mov_number)}\n' + else: + sql_command = f''' + INSERT INTO is_able_to_play (work_id, mov_id, pianist_id) + VALUES ({work_id}, {mov_number}, {self.user}) + ''' + self.db_agent.execute(sql_command) + resultstring += f'{work.pretty_mov(mov_number)}\n' return resultstring def remove_work_as_mastered(self, arguments):