def _render_obj_from_db(self, obj_class, obj_rows, field_names=None, include_backrefs_children=False):
    ref_fields = obj_class.ref_fields
    backref_fields = obj_class.backref_fields
    children_fields = obj_class.children_fields
    list_fields = obj_class.prop_list_fields
    map_fields = obj_class.prop_map_fields
    prop_fields = (obj_class.prop_fields - (list_fields | map_fields))
    results = {}
    for (obj_uuid, obj_cols) in list(obj_rows.items()):
        if (('type' not in obj_cols) or ('fq_name' not in obj_cols)):
            continue
        if (obj_class.object_type != obj_cols.pop('type')[0]):
            continue
        id_perms_ts = 0
        row_latest_ts = 0
        result = {}
        result['uuid'] = obj_uuid
        result['fq_name'] = obj_cols.pop('fq_name')[0]
        for col_name in list(obj_cols.keys()):
            if self._is_parent(col_name):
                (_, _, parent_uuid) = col_name.split(':')
                try:
                    result['parent_type'] = obj_cols['parent_type'][0]
                except KeyError:
                    pass
                result['parent_uuid'] = parent_uuid
                continue
            if self._is_prop(col_name):
                (_, prop_name) = col_name.split(':')
                if (prop_name == 'id_perms'):
                    id_perms_ts = obj_cols[col_name][1]
                if ((prop_name not in prop_fields) or (field_names and (prop_name not in field_names))):
                    continue
                result[prop_name] = obj_cols[col_name][0]
                continue
            if self._is_prop_list(col_name):
                (_, prop_name, prop_elem_position) = col_name.split(':')
                if (field_names and (prop_name not in field_names)):
                    continue
                if obj_class.prop_list_field_has_wrappers[prop_name]:
                    prop_field_types = obj_class.prop_field_types[prop_name]
                    wrapper_type = prop_field_types['xsd_type']
                    wrapper_cls = self._get_xsd_class(wrapper_type)
                    wrapper_field = wrapper_cls.attr_fields[0]
                    if (prop_name not in result):
                        result[prop_name] = {wrapper_field: []}
                    result[prop_name][wrapper_field].append((obj_cols[col_name][0], prop_elem_position))
                else:
                    if (prop_name not in result):
                        result[prop_name] = []
                    result[prop_name].append((obj_cols[col_name][0], prop_elem_position))
                continue
            if self._is_prop_map(col_name):
                (_, prop_name, _) = col_name.split(':', 2)
                if (field_names and (prop_name not in field_names)):
                    continue
                if obj_class.prop_map_field_has_wrappers[prop_name]:
                    prop_field_types = obj_class.prop_field_types[prop_name]
                    wrapper_type = prop_field_types['xsd_type']
                    wrapper_cls = self._get_xsd_class(wrapper_type)
                    wrapper_field = wrapper_cls.attr_fields[0]
                    if (prop_name not in result):
                        result[prop_name] = {wrapper_field: []}
                    result[prop_name][wrapper_field].append(obj_cols[col_name][0])
                else:
                    if (prop_name not in result):
                        result[prop_name] = []
                    result[prop_name].append(obj_cols[col_name][0])
                continue
            if self._is_children(col_name):
                (_, child_type, child_uuid) = col_name.split(':')
                if (field_names and (('%ss' % child_type) not in field_names)):
                    continue
                if ((child_type + 's') not in children_fields):
                    continue
                child_tstamp = obj_cols[col_name][1]
                try:
                    self._read_child(result, obj_uuid, child_type, child_uuid, child_tstamp)
                except NoIdError:
                    continue
                continue
            if self._is_ref(col_name):
                (_, ref_type, ref_uuid) = col_name.split(':')
                if (((ref_type + '_refs') not in ref_fields) or (field_names and ((ref_type + '_refs') not in field_names))):
                    continue
                self._read_ref(result, obj_uuid, ref_type, ref_uuid, obj_cols[col_name][0])
                continue
            if self._is_backref(col_name):
                (_, back_ref_type, back_ref_uuid) = col_name.split(':')
                if ((back_ref_type + '_back_refs') not in backref_fields):
                    continue
                if (field_names and (('%s_back_refs' % back_ref_type) not in field_names)):
                    continue
                try:
                    self._read_back_ref(result, obj_uuid, back_ref_type, back_ref_uuid, obj_cols[col_name][0])
                except NoIdError:
                    continue
                continue
            if self._is_metadata(col_name):
                (_, meta_type) = col_name.split(':')
                if (meta_type == 'latest_col_ts'):
                    row_latest_ts = obj_cols[col_name][1]
                continue
        for child_field in obj_class.children_fields:
            if (child_field not in result):
                continue
            sorted_children = sorted(result[child_field], key=itemgetter('tstamp'))
            result[child_field] = sorted_children
            [child.pop('tstamp') for child in result[child_field]]
        for prop_name in (obj_class.prop_list_fields & set(result.keys())):
            if isinstance(result[prop_name], list):
                result[prop_name] = [el[0] for el in sorted(result[prop_name], key=itemgetter(1))]
            elif isinstance(result[prop_name], dict):
                (wrapper, unsorted_list) = result[prop_name].popitem()
                result[prop_name][wrapper] = [el[0] for el in sorted(unsorted_list, key=itemgetter(1))]
        results[obj_uuid] = {'obj_dict': result, 'id_perms_ts': id_perms_ts}
        if include_backrefs_children:
            results[obj_uuid]['row_latest_ts'] = row_latest_ts
    return results
def _render_obj_from_db(self, obj_class, obj_rows, field_names=None, include_backrefs_children=False):
    ref_fields = obj_class.ref_fields
    backref_fields = obj_class.backref_fields
    children_fields = obj_class.children_fields
    list_fields = obj_class.prop_list_fields
    map_fields = obj_class.prop_map_fields
    prop_fields = (obj_class.prop_fields - (list_fields | map_fields))
    results = {}
    for (obj_uuid, obj_cols) in list(obj_rows.items()):
        if (('type' not in obj_cols) or ('fq_name' not in obj_cols)):
            continue
        if (obj_class.object_type != obj_cols.pop('type')[0]):
            continue
        id_perms_ts = 0
        row_latest_ts = 0
        result = {}
        result['uuid'] = obj_uuid
        result['fq_name'] = obj_cols.pop('fq_name')[0]
        for col_name in list(obj_cols.keys()):
            if self._is_parent(col_name):
                (_, _, parent_uuid) = col_name.split(':')
                try:
                    result['parent_type'] = obj_cols['parent_type'][0]
                except KeyError:
                    pass
                result['parent_uuid'] = parent_uuid
                continue
            if self._is_prop(col_name):
                (_, prop_name) = col_name.split(':')
                if (prop_name == 'id_perms'):
                    id_perms_ts = obj_cols[col_name][1]
                if ((prop_name not in prop_fields) or (field_names and (prop_name not in field_names))):
                    continue
                result[prop_name] = obj_cols[col_name][0]
                continue
            if self._is_prop_list(col_name):
                (_, prop_name, prop_elem_position) = col_name.split(':')
                if (field_names and (prop_name not in field_names)):
                    continue
                if obj_class.prop_list_field_has_wrappers[prop_name]:
                    prop_field_types = obj_class.prop_field_types[prop_name]
                    wrapper_type = prop_field_types['xsd_type']
                    wrapper_cls = self._get_xsd_class(wrapper_type)
                    wrapper_field = wrapper_cls.attr_fields[0]
                    if (prop_name not in result):
                        result[prop_name] = {wrapper_field: []}
                    result[prop_name][wrapper_field].append((obj_cols[col_name][0], prop_elem_position))
                else:
                    if (prop_name not in result):
                        result[prop_name] = []
                    result[prop_name].append((obj_cols[col_name][0], prop_elem_position))
                continue
            if self._is_prop_map(col_name):
                (_, prop_name, _) = col_name.split(':', 2)
                if (field_names and (prop_name not in field_names)):
                    continue
                if obj_class.prop_map_field_has_wrappers[prop_name]:
                    prop_field_types = obj_class.prop_field_types[prop_name]
                    wrapper_type = prop_field_types['xsd_type']
                    wrapper_cls = self._get_xsd_class(wrapper_type)
                    wrapper_field = wrapper_cls.attr_fields[0]
                    if (prop_name not in result):
                        result[prop_name] = {wrapper_field: []}
                    result[prop_name][wrapper_field].append(obj_cols[col_name][0])
                else:
                    if (prop_name not in result):
                        result[prop_name] = []
                    result[prop_name].append(obj_cols[col_name][0])
                continue
            if self._is_children(col_name):
                (_, child_type, child_uuid) = col_name.split(':')
                if (field_names and (('%ss' % child_type) not in field_names)):
                    continue
                if ((child_type + 's') not in children_fields):
                    continue
                child_tstamp = obj_cols[col_name][1]
                try:
                    self._read_child(result, obj_uuid, child_type, child_uuid, child_tstamp)
                except NoIdError:
                    continue
                continue
            if self._is_ref(col_name):
                (_, ref_type, ref_uuid) = col_name.split(':')
                if (((ref_type + '_refs') not in ref_fields) or (field_names and ((ref_type + '_refs') not in field_names))):
                    continue
                self._read_ref(result, obj_uuid, ref_type, ref_uuid, obj_cols[col_name][0])
                continue
            if self._is_backref(col_name):
                (_, back_ref_type, back_ref_uuid) = col_name.split(':')
                if ((back_ref_type + '_back_refs') not in backref_fields):
                    continue
                if (field_names and (('%s_back_refs' % back_ref_type) not in field_names)):
                    continue
                try:
                    self._read_back_ref(result, obj_uuid, back_ref_type, back_ref_uuid, obj_cols[col_name][0])
                except NoIdError:
                    continue
                continue
            if self._is_metadata(col_name):
                (_, meta_type) = col_name.split(':')
                if (meta_type == 'latest_col_ts'):
                    row_latest_ts = obj_cols[col_name][1]
                continue
        for child_field in obj_class.children_fields:
            if (child_field not in result):
                continue
            sorted_children = sorted(result[child_field], key=itemgetter('tstamp'))
            result[child_field] = sorted_children
            [child.pop('tstamp') for child in result[child_field]]
        for prop_name in (obj_class.prop_list_fields & set(result.keys())):
            if isinstance(result[prop_name], list):
                result[prop_name] = [el[0] for el in sorted(result[prop_name], key=itemgetter(1))]
            elif isinstance(result[prop_name], dict):
                (wrapper, unsorted_list) = result[prop_name].popitem()
                result[prop_name][wrapper] = [el[0] for el in sorted(unsorted_list, key=itemgetter(1))]
        results[obj_uuid] = {'obj_dict': result, 'id_perms_ts': id_perms_ts}
        if include_backrefs_children:
            results[obj_uuid]['row_latest_ts'] = row_latest_ts
    return results