Skip to content

Commit

Permalink
Fix human-readable name for ImageMetadata
Browse files Browse the repository at this point in the history
Fixes "IndexError at /en/mispoes/objects/, pop from empty list" error.
  • Loading branch information
praseodym committed Aug 4, 2023
1 parent 8a49ba4 commit dfadacf
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions octopoes/octopoes/models/ooi/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,17 @@ def format_reference_human_readable(cls, reference: Reference) -> str:
class ImageMetadata(OOI):
object_type: Literal["ImageMetadata"] = "ImageMetadata"

resource: Reference = ReferenceField(HTTPResource, max_issue_scan_level=0, max_inherit_scan_level=4)
resource: Reference = ReferenceField(HostnameHTTPURL, max_issue_scan_level=0, max_inherit_scan_level=4)
image_info: Dict

_natural_key_attrs = ["resource"]
_reverse_relation_names = {"resource": "ImageMetaData"}

@classmethod
def format_reference_human_readable(cls, reference: Reference) -> str:
t = reference.tokenized

port = f":{t.resource.web_url.port}" if t.resource.web_url.port else ""
try:
netloc = t.resource.web_url.netloc.address
except KeyError:
netloc = t.resource.web_url.netloc.name

web_url = f"{t.resource.web_url.scheme}://{netloc}{port}{t.resource.web_url.path}"
address = t.resource.website.ip_service.ip_port.address.address

return f"{web_url} @ {address}"
tokenized = reference.tokenized.resource
port = f":{tokenized.port}" if tokenized.port else ""
return f"{tokenized.scheme}://{tokenized.netloc.name}{port}{tokenized.path}"


class RESTAPI(OOI):
Expand Down

0 comments on commit dfadacf

Please sign in to comment.