def convert_identifiers_to_references( channel_store: Dict, channel_identifiers: List[types.ChannelResourceIdentifier] ) -> List[types.ChannelReference]: channel_references: List[types.ChannelReference] = [] for ci in channel_identifiers: channel_data: Optional[Dict] = None for c in channel_store.values(): if ci.key and c["key"] == ci.key: channel_data = c break if ci.id and c["id"] == ci.id: channel_data = c break if not channel_data: raise InternalUpdateError("Channel not found.") channel: types.Channel = ChannelSchema().load(data=channel_data) if types.ChannelRoleEnum.PRODUCT_DISTRIBUTION not in channel.roles: raise InternalUpdateError( "Channel does not have product distribution role.") channel_references.append(types.ChannelReference(id=channel.id)) return channel_references
def post_load(self, data, **kwargs): del data["type_id"] return types.ChannelReference(**data)