Fix sqlalchemy grouping on v1 storage

This fixes "CompileError: Can't resolve label reference for
ORDER BY / GROUP BY." error messages raised by sqlalchemy when the groupby
expression includes a comma.

Change-Id: Ia253175b45b8222aaee415ea535fa4102312be5a
(cherry picked from commit 5fef2d68f3)
This commit is contained in:
Luka Peschke 2019-06-04 15:21:05 +02:00
parent 08b1009d46
commit df869e4588
2 changed files with 7 additions and 1 deletions

View File

@ -127,7 +127,7 @@ class SQLAlchemyStorage(storage.BaseStorage):
self.frame_model.end <= end,
self.frame_model.res_type != '_NO_DATA_')
if groupby:
q = q.group_by(groupby)
q = q.group_by(sqlalchemy.sql.text(groupby))
# Order by sum(rate)
q = q.order_by(sqlalchemy.func.sum(self.frame_model.rate))

View File

@ -0,0 +1,6 @@
---
fixes:
- |
``CompileError: Can't resolve label reference for ORDER BY / GROUP BY.``
errors that were sometimes raised by SQLAlchemy when using the v1 storage
backend and grouping on ``tenant_id`` and ``res_type`` have been fixed.