""" LabelParticipant model; uses Neo4j. """ import uuid import connector_neo4j from flask import g def get_brand_by_lp_uuid(lp_uuid: uuid.UUID) -> str | None: """ Returns company brand associated with the label participant, or None if 1) it can't be retrieved for whatever reason or 2) there are more than one, since we can't know how to resolve that """ session = connector_neo4j.get_session() result = session.run( """ MATCH (lp:LabelParticipant {uuid: $lp_uuid})<-[:HAS_LABEL_PARTICIPANT] -()<-[*0..1]-(v:Vendor)<-[:HAS_LABEL]-(c:CompanyBrand) RETURN c.name """, lp_uuid=lp_uuid, ) brands = list(set([r.get('c.name') for r in result.data()])) if len(brands) != 1: g.log.error( f'Found {len(brands)} brands for label participant {lp_uuid}', ) return None return brands[0]