Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions hydra_base/lib/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,54 +1259,61 @@ def get_all_resource_attributes(ref_key, network_id, template_id=None, **kwargs)

ref_key_norm = ref_key.upper()

# If a template_id is provided, resolve attr_ids via get_template() so that
# inherited type attributes (from parent templates/types) are included.
attr_ids = None
if template_id is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work due to the inheritance structure in templates.
You need to call the get_template function in the template module to return the full inherited template structure, then extract the type attributes from there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c798865. The direct TypeAttr/TemplateType DB query is replaced with a call to get_template(), which walks the full inheritance tree via get_types(). The attr_ids are then extracted from all templatetypes (including inherited ones) and applied as the SQL-level filter — matching the same pattern used in get_template_attributes().

import hydra_base.lib.template as templatelib
template = templatelib.get_template(template_id, **kwargs)
attr_ids = list({ta.attr_id for tt in template.templatetypes for ta in tt.typeattrs})
if not attr_ids:
return []

if ref_key_norm == 'NODE':
results = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
qry = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
join(Node, Node.id == ResourceAttr.node_id).\
join(Attr, Attr.id == ResourceAttr.attr_id).\
filter(
ResourceAttr.node_id != None,
Node.network_id == network_id,
ResourceAttr.ref_key == ref_key_norm).all()
resource_attrs = results
ResourceAttr.ref_key == ref_key_norm)
if attr_ids is not None:
qry = qry.filter(ResourceAttr.attr_id.in_(attr_ids))
resource_attrs = qry.all()

elif ref_key_norm == 'LINK':
results = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
qry = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
join(Link, Link.id == ResourceAttr.link_id).\
join(Attr, Attr.id == ResourceAttr.attr_id).\
filter(
ResourceAttr.link_id != None,
Link.network_id == network_id,
ResourceAttr.ref_key == ref_key_norm).all()
resource_attrs = results
ResourceAttr.ref_key == ref_key_norm)
if attr_ids is not None:
qry = qry.filter(ResourceAttr.attr_id.in_(attr_ids))
resource_attrs = qry.all()

elif ref_key_norm == 'GROUP':
results = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
qry = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
join(ResourceGroup, ResourceGroup.id == ResourceAttr.group_id).\
join(Attr, Attr.id == ResourceAttr.attr_id).\
filter(
ResourceAttr.group_id != None,
ResourceGroup.network_id == network_id,
ResourceAttr.ref_key == ref_key_norm).all()
resource_attrs = results
ResourceAttr.ref_key == ref_key_norm)
if attr_ids is not None:
qry = qry.filter(ResourceAttr.attr_id.in_(attr_ids))
resource_attrs = qry.all()

elif ref_key_norm == 'NETWORK':
results = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
qry = db.DBSession.query(ResourceAttr, Attr.name, Attr.id, Attr.description).\
join(Attr, Attr.id == ResourceAttr.attr_id).\
filter(
ResourceAttr.network_id == network_id,
ResourceAttr.ref_key == ref_key_norm).all()
resource_attrs = results

if template_id is not None:
attr_ids = []
rs = db.DBSession.query(TypeAttr).join(
TemplateType,
TemplateType.id == TypeAttr.type_id).filter(
TemplateType.template_id == template_id).all()
for r in rs:
attr_ids.append(r.attr_id)

resource_attrs = [ra for ra in resource_attrs if ra[0].attr_id in attr_ids]
ResourceAttr.ref_key == ref_key_norm)
if attr_ids is not None:
qry = qry.filter(ResourceAttr.attr_id.in_(attr_ids))
resource_attrs = qry.all()

# Convert results to JSONObjects with attribute data included
result_objects = []
Expand Down