(condition: Condition)
| 545 | |
| 546 | |
| 547 | def _parse_references_condition(condition: Condition) -> None: |
| 548 | if condition.operator not in _L_OPS + _D_OPS + _E_OPS: |
| 549 | raise FilteringException( |
| 550 | "'references' only supports list, dict, and existence operators.", |
| 551 | ) |
| 552 | |
| 553 | if condition.operator in _L_OPS + _E_OPS and condition.key is not None: |
| 554 | raise FilteringException( |
| 555 | "'references' key is only supported for dict operators.", |
| 556 | ) |
| 557 | |
| 558 | if condition.operator in _E_OPS and condition.value is not None: |
| 559 | raise FilteringException( |
| 560 | "'references' value is not supported for existence operators.", |
| 561 | ) |
| 562 | |
| 563 | if condition.operator in _L_OPS: |
| 564 | if not isinstance(condition.value, list): |
| 565 | raise FilteringException( |
| 566 | "'references' value must be one or more (possibly partial) references.", |
| 567 | ) |
| 568 | |
| 569 | if not all(isinstance(v, dict) for v in condition.value): |
| 570 | raise FilteringException( |
| 571 | "'references' value must be one or more (possibly partial) references.", |
| 572 | ) |
| 573 | |
| 574 | if condition.operator in _D_OPS: |
| 575 | if not isinstance(condition.key, str) or not condition.key.startswith( |
| 576 | "attributes." |
| 577 | ): |
| 578 | raise FilteringException( |
| 579 | "'references' key must be a string in dot notation starting with 'attributes'.", |
| 580 | ) |
| 581 | |
| 582 | if condition.operator in _E_OPS: |
| 583 | pass |
| 584 | elif condition.operator in _L_OPS: |
| 585 | try: |
| 586 | _values = [] |
| 587 | |
| 588 | for v in condition.value: |
| 589 | v: dict |
| 590 | |
| 591 | ref_id = v.get("id") |
| 592 | ref_slug = v.get("slug") |
| 593 | |
| 594 | if ref_id: |
| 595 | _values.append( |
| 596 | Reference( |
| 597 | id=parse_ref_id_to_uuid(ref_id), |
| 598 | ).model_dump(exclude_none=True) |
| 599 | ) |
| 600 | |
| 601 | if ref_slug: |
| 602 | _values.append( |
| 603 | Reference( |
| 604 | slug=parse_ref_slug_to_str(ref_slug), |
no test coverage detected