diff --git a/ceilometer/event/storage/impl_sqlalchemy.py b/ceilometer/event/storage/impl_sqlalchemy.py index e0497b42..46368af3 100644 --- a/ceilometer/event/storage/impl_sqlalchemy.py +++ b/ceilometer/event/storage/impl_sqlalchemy.py @@ -266,14 +266,18 @@ class Connection(base.Connection): query = query.join(trait_subq, trait_subq.c.ev_id == models.Event.id) if event_filter.admin_proj: - admin_q = session.query(models.TraitText).filter( + no_proj_q = session.query(models.TraitText.event_id).filter( models.TraitText.key == 'project_id') - query = query.filter(sa.or_(~sa.exists().where( - models.Event.id == admin_q.subquery().c.event_id), - sa.and_( + admin_q = (session.query(models.TraitText.event_id).filter( + ~sa.exists().where(models.TraitText.event_id == + no_proj_q.subquery().c.event_id)).union( + session.query(models.TraitText.event_id).filter(sa.and_( models.TraitText.key == 'project_id', models.TraitText.value == event_filter.admin_proj, - models.Event.id == models.TraitText.event_id))) + models.Event.id == models.TraitText.event_id)))) + query = query.filter(sa.exists().where( + models.Event.id == + admin_q.subquery().c.trait_text_event_id)) if event_filter_conditions: query = query.filter(sa.and_(*event_filter_conditions)) @@ -283,7 +287,7 @@ class Connection(base.Connection): for (id_, generated, message_id, desc, raw) in query.add_columns( models.Event.generated, models.Event.message_id, - models.EventType.desc, models.Event.raw).distinct().all(): + models.EventType.desc, models.Event.raw).all(): event_list[id_] = api_models.Event(message_id, desc, generated, [], raw) # Query all traits related to events.