From 93a0217d5f0d88f61ea3411430d954ced677b320 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 20 Jul 2020 20:28:10 +0200 Subject: [PATCH] Fix for #1530 (Handle improper migrated database with config_mature_content_tags NULL instead of "") --- cps/config_sql.py | 10 +++++++--- cps/ub.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index 1135516d..b965eace 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -102,7 +102,6 @@ class _Settings(_Base): config_kobo_proxy = Column(Boolean, default=False) - config_ldap_provider_url = Column(String, default='example.org') config_ldap_port = Column(SmallInteger, default=389) config_ldap_authentication = Column(SmallInteger, default=constants.LDAP_AUTH_SIMPLE) @@ -215,8 +214,13 @@ class _ConfigSQL(object): return self.show_element_new_user(constants.DETAIL_RANDOM) def list_denied_tags(self): - mct = self.config_denied_tags.split(",") - return [t.strip() for t in mct] + try: + mct = self.config_denied_tags.split(",") + return [t.strip() for t in mct] + except AttributeError: + # Fix for improper migrated database with config_mature_content_tags NULL instead of "" + self.config_denied_tags = "" + return [''] def list_allowed_tags(self): mct = self.config_allowed_tags.split(",") diff --git a/cps/ub.py b/cps/ub.py index 1a2c260a..8fcec1af 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -176,8 +176,14 @@ class UserBase: return self.check_visibility(constants.DETAIL_RANDOM) def list_denied_tags(self): - mct = self.denied_tags.split(",") - return [t.strip() for t in mct] + try: + mct = self.denied_tags.split(",") + return [t.strip() for t in mct] + except AttributeError: + # Fix for improper migrated database with config_mature_content_tags NULL instead of "" + self.denied_tags="" + return [''] + def list_allowed_tags(self): mct = self.allowed_tags.split(",") @@ -563,8 +569,8 @@ def migrate_Database(session): conn = engine.connect() conn.execute("ALTER TABLE user ADD column `denied_tags` String DEFAULT ''") conn.execute("ALTER TABLE user ADD column `allowed_tags` String DEFAULT ''") - conn.execute("ALTER TABLE user ADD column `denied_column_value` DEFAULT ''") - conn.execute("ALTER TABLE user ADD column `allowed_column_value` DEFAULT ''") + conn.execute("ALTER TABLE user ADD column `denied_column_value` String DEFAULT ''") + conn.execute("ALTER TABLE user ADD column `allowed_column_value` String DEFAULT ''") session.commit() try: session.query(exists().where(User.series_view)).scalar()