From 812fc41c6ec1ba42efe07e1faad63c40d1103adf Mon Sep 17 00:00:00 2001 From: Davor Date: Tue, 21 Jun 2022 17:33:04 +0200 Subject: [PATCH] Fix checking if app exists before inserting into DB --- cliapp/cliapp/cli.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cliapp/cliapp/cli.py b/cliapp/cliapp/cli.py index cd24595..9c16f09 100644 --- a/cliapp/cliapp/cli.py +++ b/cliapp/cliapp/cli.py @@ -57,13 +57,15 @@ def create_app(slug, name): obj.name = name obj.slug = slug - app = db.session.query(App).filter_by(slug=slug).first() + app_obj = App.query.filter_by(slug=slug).first() - if app is not None: - db.session.add(obj) - db.session.commit() - else: + if app_obj: current_app.logger.info(f"App definition: {name} ({slug}) already exists in database") + return + + db.session.add(obj) + db.session.commit() + current_app.logger.info(f"App definition: {name} ({slug}) created")