layerindex: email maintainers who opt in when their layer fails
PATCH 1/1 layerindex: email maintainers who opt in when their layer fails
Maintainers only found out that their layer failed to parse by looking at its update history. Add "Email me when my layers fail to parse" to the profile page, off by default. At the end of each update, email the users who opted in and are an active maintainer of a layer branch that has errors in this update but had none in its previous one, with a link to the update's log. If more than half of the layer branches of a large update newly fail, the problem is probably the update itself, so email the site admins once instead of the maintainers.
[YOCTO #11196]
AI-Generated: Claude Opus 5.5
---
This adds migration 0058, so it applies on top of "[PATCH 0/2] Let maintainers change their email address safely" (bug 11195, migration 0057) and the 14348 series it builds on, and on master-next.
Applying the rule to the last two updates of a test instance loaded with a copy of the layers.openembedded.org database: on 2026-11-13, 0 of 11 layer branches newly failed, so no emails; on 2026-11-14, 45 of 54 did, so one email to the admins and none to maintainers. That spike came from "update: record errors in a layer's first parse against the layer" recording dependency failures as layer updates for the first time, which the admin rule is meant for.
layerindex/forms.py | 3 + .../0058_userprofile_notify_parse_errors.py | 16 ++++ layerindex/models.py | 2 + layerindex/notify.py | 70 ++++++++++++++++ layerindex/update.py | 3 + layerindex/views.py | 5 ++ tests/test_parse_error_mail.py | 82 +++++++++++++++++++ tests/test_profile_email.py | 11 ++- 8 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 layerindex/migrations/0058_userprofile_notify_parse_errors.py create mode 100644 layerindex/notify.py create mode 100644 tests/test_parse_error_mail.py
layerindex/forms.py +3 -0
@@ -211,6 +211,8 @@ class EditNoteForm(StyledModelForm): class EditProfileForm(StyledModelForm): + notify_parse_errors = forms.BooleanField(label='Email me when my layers fail to parse', required=False, + help_text='Sent when a layer branch you maintain starts to fail') current_password = forms.CharField(label='Current password', required=False, strip=False, widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}), help_text='Needed to change your email address')
@@ -233,6 +235,7 @@ class EditProfileForm(StyledModelForm): 'autocomplete': 'off' }) user = kwargs.get("instance") + self.fields['notify_parse_errors'].initial = UserProfile.objects.filter(user=user, notify_parse_errors=True).exists() try: self.fields['security_question_1'].initial=user.userprofile.securityquestionanswer_set.all()[0].security_question self.fields['security_question_2'].initial=user.userprofile.securityquestionanswer_set.all()[1].security_question
layerindex/migrations/0058_userprofile_notify_parse_errors.py new file +16 -0
@@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('layerindex', '0057_userprofile_previous_email'), + ] + + operations = [ + migrations.AddField( + model_name='userprofile', + name='notify_parse_errors', + field=models.BooleanField(default=False, help_text='Sent when a layer branch you maintain starts to fail', verbose_name='Email me when my layers fail to parse'), + ), + ]
layerindex/models.py +2 -0
@@ -965,6 +965,8 @@ class UserProfile(models.Model): # The confirmed email address before a change of address that has not # been confirmed yet, to move the user's maintainer records once it is previous_email = models.CharField(max_length=255, blank=True) + notify_parse_errors = models.BooleanField('Email me when my layers fail to parse', default=False, + help_text='Sent when a layer branch you maintain starts to fail') def pending_maintainer_records(self): """Maintainer records still under the user's previous address"""
layerindex/notify.py new file +70 -0
70 lines not on this page · raw message
layerindex/update.py +3 -0
@@ -621,6 +621,9 @@ def main(): update_purge_days = getattr(settings, 'UPDATE_PURGE_DAYS', 30) Update.objects.filter(started__lte=datetime.now()-timedelta(days=update_purge_days)).delete() + from layerindex.notify import notify_parse_errors + notify_parse_errors(update, logger) + sys.exit(0)
layerindex/views.py +5 -0
@@ -1056,6 +1056,11 @@ class EditProfileFormView(LoginRequiredMixin, SuccessMessageMixin, UpdateView): def form_valid(self, form): self.object = form.save() + if 'notify_parse_errors' in form.changed_data: + profile, _ = UserProfile.objects.get_or_create(user=self.user) + profile.notify_parse_errors = form.cleaned_data['notify_parse_errors'] + profile.save(update_fields=['notify_parse_errors']) + if'answer_1' in form.changed_data: # If one security answer has changed, they all have. Delete current questions and add new ones. # Don't throw an error if we are editing the super user and they don't have security questions yet.
tests/test_parse_error_mail.py new file +82 -0
82 lines not on this page · raw message
tests/test_profile_email.py +9 -2
@@ -34,9 +34,9 @@ class TestProfileEmailChange(TestCase): SecurityQuestionAnswer.objects.create(user=profile, security_question=question, answer='x') self.client.force_login(self.user) - def _post_profile(self, email, password='pw'): + def _post_profile(self, email, password='pw', **extra): hashkey = CaptchaStore.generate_key() - data = { + data = {**extra, 'current_password': password, 'username': 'someone', 'first_name': '',
@@ -147,3 +147,10 @@ class TestProfileEmailChange(TestCase): self.assertTrue(layer.user_can_edit(self.user)) self.assertEqual([m.to for m in mail.outbox], [['[email protected]']]) self.assertEqual(UserProfile.objects.get(user=self.user).previous_email, '') + + def test_opt_in_to_parse_error_mail(self): + # [YOCTO #11196] + self._post_profile('[email protected]', notify_parse_errors='on') + self.assertTrue(UserProfile.objects.get(user=self.user).notify_parse_errors) + self._post_profile('[email protected]') + self.assertFalse(UserProfile.objects.get(user=self.user).notify_parse_errors)
base-commit: 08e58cdece30019a6f9e5d14af16ebe20afa6177
prerequisite-patch-id: 6c677e4190187d389840d2a94b4d857a69c0d647
prerequisite-patch-id: 282bc018dfe6528deb8363d3cbd1b31671c4b606
prerequisite-patch-id: 41ede4992addb0d7f364a079e773a77943b6341f
prerequisite-patch-id: 51420179b7abf0bd91736545eb4a692058cca8b4
Signature · 1 line
2.56.0