Skip to content

Commit

Permalink
Create email settings for new TestPlan. Fix #181
Browse files Browse the repository at this point in the history
also change post_delete to pre_delete signal.

Explanation:

There is a TestPlan object and the TestPlan.email_settings
attribute points to TestPlanEmailSettings object. When we
delete the TP Django will first delete the TPES object, then
initiate TP.delete() and at the end of it send the post_delete
signal. Upon receiving of this signal the TPES object doesn't
exist anymore and trying to access it via TP.emailing property
tries to create a new TPES object pointing to the TP instance.

Because it has already been deleted from the DB MySQL integrity
check fails. The only way is to notify users about plan deletion
using a pre_delete signal because all objects are still available
in the database.

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>
  • Loading branch information
atodorov committed Apr 26, 2017
1 parent 6538c6d commit 5fa9891
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tcms/testplans/models.py
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db.models import Max
from django.db.models.signals import post_save, post_delete, pre_save
from django.db.models.signals import post_save, pre_delete, pre_save
from uuslug import slugify

from tcms.management.models import Version
Expand Down Expand Up @@ -358,14 +358,14 @@ class Meta:

def _listen():
post_save.connect(plan_watchers.on_plan_save, TestPlan)
post_delete.connect(plan_watchers.on_plan_delete, TestPlan)
pre_delete.connect(plan_watchers.on_plan_delete, TestPlan)
pre_save.connect(plan_watchers.pre_save_clean, TestPlan)


def _disconnect_signals():
""" used in testing """
post_save.disconnect(plan_watchers.on_plan_save, TestPlan)
post_delete.disconnect(plan_watchers.on_plan_delete, TestPlan)
pre_delete.disconnect(plan_watchers.on_plan_delete, TestPlan)
pre_save.disconnect(plan_watchers.pre_save_clean, TestPlan)


Expand Down
3 changes: 3 additions & 0 deletions tcms/testplans/views.py
Expand Up @@ -126,6 +126,9 @@ def new(request, template_name='plan/new.html'):
for env_group in env_groups:
tp.add_env_group(env_group=env_group)

# create emailing settings to avoid Issue #181 on MySQL
tp.emailing.save()

return HttpResponseRedirect(
reverse('tcms.testplans.views.get', args=[tp.plan_id, ])
)
Expand Down

0 comments on commit 5fa9891

Please sign in to comment.