New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to delete testplan or product #181

Closed
nivw opened this Issue Apr 24, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@nivw

nivw commented Apr 24, 2017

After clean install from git, I created product Mile_stone_1 and define a Classification for it.
I then create a test plan for it.
I then try to remove both the product and the test plan and fail:
http://nivw-nitrate:8000/admin/management/product/2/delete/

Are you sure you want to delete the product "Mile_stone_1"? All of the following related items will be deleted:

Product: Mile_stone_1
Version: 1
Test plan: basic 1
Test plan text: TestPlanText object
Test plan email settings: TestPlanEmailSettings object
Test plan: Functional Acceptance Tests
Test plan email settings: TestPlanEmailSettings object
Version: unspecified
Build: unspecified
Test case category: --default--
Yes, I'm sure

I click yes:

IntegrityError at /admin/management/product/2/delete/
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Request Method: POST
Request URL: http://nivw-nitrate:8000/admin/management/product/2/delete/
Django Version: 1.8.14
Exception Type: IntegrityError
Exception Value:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Exception Location: /usr/lib64/python2.7/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/root/Nitrate',
'/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/nitrate-3.8.18-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib/python2.7/site-packages',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/root/Nitrate/tcms/core/lib']
Server time: Mon, 24 Apr 2017 17:52:22 +0800
Traceback Switch to copy-and-paste view

/usr/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/views/decorators/cache.py in _wrapped_view_func
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/sites.py in inner
return view(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapper
return bound_func(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in _wrapped_view
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in bound_func
return func.get(self, type(self))(*args2, **kwargs2) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/utils/decorators.py in inner
return func(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in delete_view
self.delete_model(request, obj) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/contrib/admin/options.py in delete_model
obj.delete() ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/base.py in delete
collector.delete() ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/deletion.py in delete
sender=model, instance=obj, using=self.using ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/dispatch/dispatcher.py in send
response = receiver(signal=self, sender=sender, **named) ...
▶ Local vars
/root/Nitrate/tcms/testplans/signals.py in on_plan_delete
if instance.emailing.notify_on_plan_delete: ...
▶ Local vars
/root/Nitrate/tcms/testplans/models.py in _get_email_conf
return TestPlanEmailSettings.objects.create(plan=self) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/manager.py in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/query.py in create
obj.save(force_insert=True, using=self.db) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/base.py in save
force_update=force_update, update_fields=update_fields) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/base.py in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/base.py in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/base.py in _do_insert
using=using, raw=raw) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/manager.py in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/query.py in _insert
return query.get_compiler(using=using).execute_sql(return_id) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql
cursor.execute(sql, params) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return super(CursorDebugWrapper, self).execute(sql, params) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return self.cursor.execute(sql, params) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/utils.py in exit
six.reraise(dj_exc_type, dj_exc_value, traceback) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return self.cursor.execute(sql, params) ...
▶ Local vars
/usr/lib/python2.7/site-packages/django/db/backends/mysql/base.py in execute
return self.cursor.execute(query, args) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py in execute
self.errorhandler(self, exc, value) ...
▶ Local vars
/usr/lib64/python2.7/site-packages/MySQLdb/connections.py in defaulterrorhandler
raise errorclass, errorvalue ...
▶ Local vars

@nivw

This comment has been minimized.

Show comment
Hide comment
@nivw

nivw Apr 24, 2017

On issuing http://nivw-nitrate:8000/admin/testplans/testplan/3/delete/ :

IntegrityError at /admin/testplans/testplan/3/delete/
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Request Method: POST
Request URL: http://nivw-nitrate:8000/admin/testplans/testplan/3/delete/
Django Version: 1.8.14
Exception Type: IntegrityError
Exception Value:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Exception Location: /usr/lib64/python2.7/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/root/Nitrate',
'/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/nitrate-3.8.18-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib/python2.7/site-packages',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/root/Nitrate/tcms/core/lib']
Server time: Mon, 24 Apr 2017 17:56:52 +0800

nivw commented Apr 24, 2017

On issuing http://nivw-nitrate:8000/admin/testplans/testplan/3/delete/ :

IntegrityError at /admin/testplans/testplan/3/delete/
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Request Method: POST
Request URL: http://nivw-nitrate:8000/admin/testplans/testplan/3/delete/
Django Version: 1.8.14
Exception Type: IntegrityError
Exception Value:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (nitrate.testplans_testplanemailsettings, CONSTRAINT testplans_testpla_plan_id_39c35cd72f5f806b_fk_test_plans_plan_id FOREIGN KEY (plan_id) REFERENCES test_plans (plan_id))')
Exception Location: /usr/lib64/python2.7/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/root/Nitrate',
'/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/nitrate-3.8.18-py2.7.egg',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib/python2.7/site-packages',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/usr/lib/python2.7/site-packages/odf',
'/root/Nitrate/tcms/core/lib']
Server time: Mon, 24 Apr 2017 17:56:52 +0800

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Apr 24, 2017

Contributor

Thanks for this bug report. I will take a look at it later today.

Contributor

atodorov commented Apr 24, 2017

Thanks for this bug report. I will take a look at it later today.

@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Apr 24, 2017

Contributor

@nivw I think I know what the problem is and it is an easy fix but I have to write some tests for it before I create a PR (probably tomorrow).

As a workaround try editting the test plans which are about to be deleted: add some text to them, also check one of the notification checkboxes at the bottom of the edit page and SAVE. Then try to delete the product.

As far as I can tell the problem is that there is a TestPlanEmailSettings model which is a 1-to-1 relationship with TestPlan but doesn't get created automatically if you don't edit the TP and don't change notification settings. In my testing, trying to reproduce this issue I was able to reproduce when I created a TP but didn't edit it. Then looking into the DB I saw that I had a TestPlan with ID 2 and no records for TestPlanEmailSettings. Let me know how that works for you!

Contributor

atodorov commented Apr 24, 2017

@nivw I think I know what the problem is and it is an easy fix but I have to write some tests for it before I create a PR (probably tomorrow).

As a workaround try editting the test plans which are about to be deleted: add some text to them, also check one of the notification checkboxes at the bottom of the edit page and SAVE. Then try to delete the product.

As far as I can tell the problem is that there is a TestPlanEmailSettings model which is a 1-to-1 relationship with TestPlan but doesn't get created automatically if you don't edit the TP and don't change notification settings. In my testing, trying to reproduce this issue I was able to reproduce when I created a TP but didn't edit it. Then looking into the DB I saw that I had a TestPlan with ID 2 and no records for TestPlanEmailSettings. Let me know how that works for you!

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 25, 2017

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 25, 2017

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 25, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!
@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Apr 25, 2017

Contributor

@nivw I've added an automated test to try and reproduce this (I was able to reproduce by hand) but for some reason my test is not able to reproduce. It passes. Can you give more information about your DB configuration? What version, what storage engine settings, what collation ?

Contributor

atodorov commented Apr 25, 2017

@nivw I've added an automated test to try and reproduce this (I was able to reproduce by hand) but for some reason my test is not able to reproduce. It passes. Can you give more information about your DB configuration? What version, what storage engine settings, what collation ?

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Create email settings for new TestPlan. Fix #181
Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Create email settings for new TestPlan. Fix #181
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>

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

atodorov added a commit to MrSenko/Nitrate that referenced this issue Apr 26, 2017

Create email settings for new TestPlan. Fix #181
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>
@atodorov

This comment has been minimized.

Show comment
Hide comment
@atodorov

atodorov Apr 26, 2017

Contributor

@nivw you can follow the fix in #182

Contributor

atodorov commented Apr 26, 2017

@nivw you can follow the fix in #182

atodorov added a commit to MrSenko/Nitrate that referenced this issue May 24, 2017

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

atodorov added a commit to MrSenko/Nitrate that referenced this issue May 24, 2017

Create email settings for new TestPlan. Fix #181
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>

@tkdchen tkdchen added the bug label Mar 3, 2018

@tkdchen tkdchen added this to the 4.2 milestone Mar 3, 2018

@tkdchen tkdchen self-assigned this Apr 11, 2018

tkdchen added a commit to tkdchen/Nitrate that referenced this issue Apr 14, 2018

Add test for #181, fails only on MySQL
Note: on MySQL the test will fail with foreign key constraint
violation b/c TestPlanEmailSettings, which has 1-1 mapping with
TestPlan does not exist!

The failure happens when we delete the TestPlan as a result of
cascading delete of a Product. There are signal handlers for TP
which send email notifications on deletion. TP.emailing
does not exist but b/c this is a property we try to create a
TestPlanEmailSettings object which will point to the deleted TP!

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

tkdchen added a commit to tkdchen/Nitrate that referenced this issue Apr 14, 2018

Create email settings for new TestPlan
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.

Fixes #181

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>

@tkdchen tkdchen closed this in 391ede3 Apr 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment