(self, instance)
| 530 | ] |
| 531 | |
| 532 | def get_attribute(self, instance): |
| 533 | # Can't have any relationships if not created |
| 534 | if hasattr(instance, 'pk') and instance.pk is None: |
| 535 | return [] |
| 536 | |
| 537 | try: |
| 538 | relationship = get_attribute(instance, self.source_attrs) |
| 539 | except (KeyError, AttributeError) as exc: |
| 540 | if self.default is not empty: |
| 541 | return self.get_default() |
| 542 | if self.allow_null: |
| 543 | return None |
| 544 | if not self.required: |
| 545 | raise SkipField() |
| 546 | msg = ( |
| 547 | 'Got {exc_type} when attempting to get a value for field ' |
| 548 | '`{field}` on serializer `{serializer}`.\nThe serializer ' |
| 549 | 'field might be named incorrectly and not match ' |
| 550 | 'any attribute or key on the `{instance}` instance.\n' |
| 551 | 'Original exception text was: {exc}.'.format( |
| 552 | exc_type=type(exc).__name__, |
| 553 | field=self.field_name, |
| 554 | serializer=self.parent.__class__.__name__, |
| 555 | instance=instance.__class__.__name__, |
| 556 | exc=exc |
| 557 | ) |
| 558 | ) |
| 559 | raise type(exc)(msg) |
| 560 | |
| 561 | return relationship.all() if hasattr(relationship, 'all') else relationship |
| 562 | |
| 563 | def to_representation(self, iterable): |
| 564 | return [ |
nothing calls this directly
no test coverage detected