CollectionFieldSerializer throws AttributeError if Catalog Object not available
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 109
- Forks
- 107
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 4
Description
CatalogSource in a vocabulary might not serialize if the target object, out of whichever reasons, is deleted.
Extends the error handling with an AttributeError:
@adapter(ICollection, IDexterityContent, Interface)
@implementer(IFieldSerializer)
class CollectionFieldSerializer(DefaultFieldSerializer):
def __call__(self):
# Binding is necessary for named vocabularies
if IField.providedBy(self.field):
self.field = self.field.bind(self.context)
value = self.get_value()
value_type = self.field.value_type
if (
value is not None
and IChoice.providedBy(value_type)
and IVocabularyTokenized.providedBy(value_type.vocabulary)
):
values = []
for v in value:
try:
term = value_type.vocabulary.getTerm(v)
values.append({"token": term.token, "title": term.title})
except (LookupError, AttributeError):
log.warning("Term lookup error: %r" % v)
value = values
return json_compatible(value)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CollectionFieldSerializer.call shown in the issue and trace how CatalogSource terms are resolved when the target object is missing. Verify that a missing catalog object no longer raises AttributeError while valid terms still serialize with their token and title.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100