(self, fields)
| 2585 | return self.selected is not None |
| 2586 | |
| 2587 | def set_values(self, fields): |
| 2588 | self.select_related = False |
| 2589 | self.clear_deferred_loading() |
| 2590 | self.clear_select_fields() |
| 2591 | |
| 2592 | selected = {} |
| 2593 | if fields: |
| 2594 | for field in fields: |
| 2595 | self.check_alias(field) |
| 2596 | field_names = [] |
| 2597 | extra_names = [] |
| 2598 | annotation_names = [] |
| 2599 | if not self.extra and not self.annotations: |
| 2600 | # Shortcut - if there are no extra or annotations, then |
| 2601 | # the values() clause must be just field names. |
| 2602 | field_names = list(fields) |
| 2603 | selected = dict(zip(fields, range(len(fields)))) |
| 2604 | else: |
| 2605 | self.default_cols = False |
| 2606 | for f in fields: |
| 2607 | if extra := self.extra_select.get(f): |
| 2608 | extra_names.append(f) |
| 2609 | selected[f] = RawSQL(*extra) |
| 2610 | elif f in self.annotation_select: |
| 2611 | annotation_names.append(f) |
| 2612 | selected[f] = f |
| 2613 | elif f in self.annotations: |
| 2614 | if self.annotation_select: |
| 2615 | raise FieldError( |
| 2616 | f"Cannot select the '{f}' alias. It was excluded " |
| 2617 | f"by a previous values() or values_list() call. " |
| 2618 | f"Include '{f}' in that call to select it." |
| 2619 | ) |
| 2620 | else: |
| 2621 | raise FieldError( |
| 2622 | f"Cannot select the '{f}' alias. Use annotate() " |
| 2623 | f"to promote it." |
| 2624 | ) |
| 2625 | else: |
| 2626 | # Call `names_to_path` to ensure a FieldError including |
| 2627 | # annotations about to be masked as valid choices if |
| 2628 | # `f` is not resolvable. |
| 2629 | if self.annotation_select: |
| 2630 | self.names_to_path(f.split(LOOKUP_SEP), self.model._meta) |
| 2631 | selected[f] = len(field_names) |
| 2632 | field_names.append(f) |
| 2633 | self.set_extra_mask(extra_names) |
| 2634 | self.set_annotation_mask(annotation_names) |
| 2635 | else: |
| 2636 | field_names = [f.attname for f in self.model._meta.concrete_fields] |
| 2637 | selected = dict.fromkeys(field_names, None) |
| 2638 | # Selected annotations must be known before setting the GROUP BY |
| 2639 | # clause. |
| 2640 | if self.group_by is True: |
| 2641 | self.add_fields( |
| 2642 | (f.attname for f in self.model._meta.concrete_fields), False |
| 2643 | ) |
| 2644 | # Disable GROUP BY aliases to avoid orphaning references to the |
no test coverage detected