From 1a22d0cf9b168b1461e5b9ab1df93118f4bc2e01 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 27 May 2020 22:13:43 +0200 Subject: [PATCH] fix domain can be null in self-hosting # Conflicts: # app/api/views/new_custom_alias.py # app/dashboard/views/custom_alias.py --- app/api/views/new_custom_alias.py | 5 +++-- app/dashboard/views/custom_alias.py | 3 ++- app/oauth/views/authorize.py | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/api/views/new_custom_alias.py b/app/api/views/new_custom_alias.py index 202e949d..40237056 100644 --- a/app/api/views/new_custom_alias.py +++ b/app/api/views/new_custom_alias.py @@ -85,8 +85,9 @@ def new_custom_alias(): if alias_suffix.startswith("@"): alias_domain = alias_suffix[1:] domain = CustomDomain.get_by(domain=alias_domain) - LOG.d("set alias %s to domain %s", full_alias, domain) - alias.custom_domain_id = domain.id + if domain: + LOG.d("set alias %s to domain %s", full_alias, domain) + alias.custom_domain_id = domain.id db.session.commit() diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index a646acce..e4e25732 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -130,7 +130,8 @@ def custom_alias(): ) return redirect(url_for("dashboard.custom_alias")) - custom_domain_id = domain.id + if domain: + custom_domain_id = domain.id alias = Alias.create( user_id=current_user.id, diff --git a/app/oauth/views/authorize.py b/app/oauth/views/authorize.py index a076f2dd..73574745 100644 --- a/app/oauth/views/authorize.py +++ b/app/oauth/views/authorize.py @@ -192,7 +192,8 @@ def authorize(): if alias_suffix.startswith("@"): alias_domain = alias_suffix[1:] domain = CustomDomain.get_by(domain=alias_domain) - alias.custom_domain_id = domain.id + if domain: + alias.custom_domain_id = domain.id db.session.flush() flash(f"Alias {full_alias} has been created", "success")