diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py index 8fc031c4..6deeecfa 100644 --- a/lemur/certificates/service.py +++ b/lemur/certificates/service.py @@ -20,6 +20,7 @@ from lemur.common.utils import generate_private_key, truthiness from lemur.destinations.models import Destination from lemur.domains.models import Domain from lemur.extensions import metrics, sentry, signals +from lemur.models import certificate_associations from lemur.notifications.models import Notification from lemur.pending_certificates.models import PendingCertificate from lemur.plugins.base import plugins @@ -332,13 +333,13 @@ def render(args): elif 'id' in terms: query = query.filter(Certificate.id == cast(terms[1], Integer)) elif 'name' in terms: - query = query.filter( + query = query.join(certificate_associations).join(Domain).filter( or_( Certificate.name.ilike(term), Certificate.domains.any(Domain.name.ilike(term)), Certificate.cn.ilike(term), ) - ) + ).group_by(Certificate.id) else: query = database.filter(query, Certificate, terms) diff --git a/lemur/database.py b/lemur/database.py index ad3899aa..5cfe340a 100644 --- a/lemur/database.py +++ b/lemur/database.py @@ -11,11 +11,11 @@ """ from inflection import underscore from sqlalchemy import exc, func -from sqlalchemy.sql import and_, or_ from sqlalchemy.orm import make_transient +from sqlalchemy.sql import and_, or_ -from lemur.extensions import db from lemur.exceptions import AttrNotFound, DuplicateError +from lemur.extensions import db def filter_none(kwargs): @@ -273,7 +273,7 @@ def get_count(q): :param q: :return: """ - count_q = q.statement.with_only_columns([func.count()]).order_by(None) + count_q = q.statement.with_only_columns([func.count()]).group_by(None).order_by(None) count = q.session.execute(count_q).scalar() return count