|
12 | 12 | # License for the specific language governing permissions and limitations |
13 | 13 | # under the License. |
14 | 14 |
|
| 15 | +from wsme import types as wtypes |
| 16 | + |
15 | 17 | from oslo_db.sqlalchemy import models |
16 | 18 | from oslo_utils import strutils |
17 | 19 | from oslo_utils import uuidutils |
18 | 20 | import sqlalchemy as sa |
19 | 21 | from sqlalchemy.orm import collections |
20 | 22 | from sqlalchemy.orm import declarative_base |
21 | 23 |
|
| 24 | +from octavia.common import constants |
| 25 | + |
22 | 26 |
|
23 | 27 | class OctaviaBase(models.ModelBase): |
24 | 28 |
|
@@ -112,12 +116,20 @@ def to_data_model(self, _graph_nodes=None): |
112 | 116 |
|
113 | 117 | @staticmethod |
114 | 118 | def apply_filter(query, model, filters): |
| 119 | + # Convert boolean filters to proper type |
| 120 | + for key in filters: |
| 121 | + attr = getattr(model.__v2_wsme__, key, None) |
| 122 | + if isinstance(attr, wtypes.wsattr) and attr.datatype == bool: |
| 123 | + filters[key] = strutils.bool_from_string(filters[key]) |
| 124 | + # Special case for 'enabled', it's 'admin_state_up' in the WSME class |
| 125 | + # definition and the attribute has already been renamed to 'enabled' by |
| 126 | + # a previous pagination filter |
| 127 | + if constants.ENABLED in filters: |
| 128 | + filters[constants.ENABLED] = strutils.bool_from_string( |
| 129 | + filters[constants.ENABLED]) |
| 130 | + |
115 | 131 | translated_filters = {} |
116 | 132 | child_map = {} |
117 | | - # Convert enabled to proper type |
118 | | - if 'enabled' in filters: |
119 | | - filters['enabled'] = strutils.bool_from_string( |
120 | | - filters['enabled']) |
121 | 133 | for attr, name_map in model.__v2_wsme__._child_map.items(): |
122 | 134 | for k, v in name_map.items(): |
123 | 135 | if attr in filters and k in filters[attr]: |
|
0 commit comments