Bug 882311

Summary: [ALL LANG][SAM Web GUI] Unexpected error: Couldn't find Organization with ID=1 [WHERE "organizations"."task_id" IS NULL] occurred when failed deletion for the default org 'ACME_Corporation'.
Product: Red Hat Satellite Reporter: Tom McKay <tomckay>
Component: Content ManagementAssignee: Lukas Zapletal <lzap>
Status: CLOSED UPSTREAM QA Contact: Katello QA List <katello-qa-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.0.0CC: lijli, lzap, mhulan, mmccune, qe-i18n-bugs, tomckay
Target Milestone: UnspecifiedKeywords: i18n, Reopened, Triaged
Target Release: Unused   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 881568 Environment:
Last Closed: 2013-09-19 18:12:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 881568    
Bug Blocks:    

Description Tom McKay 2012-11-30 16:14:58 UTC
+++ This bug was initially created as a clone of Bug #881568 +++

Description of problem:
Unexpected error: Couldn't find Organization with ID=1 [WHERE "organizations"."task_id" IS NULL] occurred when failed deletion for the default org 'ACME_Corporation'.

Version-Release number of selected component (if applicable):
Subscription Asset Manager Version: 1.2.5-1h.el6_3

How reproducible:
100%

Steps to Reproduce:
1. Create a user and assign the default Organization 'ACME_Corporation' to it.
2. Delete the default Organization 'ACME_Corporation'.
3. Back to user name list, click on the user name that assigned to the default Organization 'ACME_Corporation' in step 1, click on Environment sub tab.

  
Actual results:
1. After failed deletion for the default org 'ACME_Corporation'. Pops-up the following message and cannot create the org 'ACME_Corporation' again:
Organization 'ACME_Corporation' already exists and either has been scheduled for deletion or failed deletion. 

2. Unexpected error: Couldn't find Organization with ID=1 [WHERE "organizations"."task_id" IS NULL] occurred when failed deletion for the default org 'ACME_Corporation'.

3. The default org 'ACME_Corporation' failed deletion from the backend db. Only can create the org 'ACME_Corporation' again on the WEB GUI & CLI after deleting the record from db by manual:

# LANG=en_US.UTF-8 psql -d katelloschema -U katellouser

Password for user katellouser:

psql (8.4.13)

Type "help" for help.

 

katelloschema-> \dt organizations

              List of relations

Schema |     Name      | Type  |    Owner   

--------+---------------+-------+-------------

public | organizations | table | katellouser

(1 row)

 

katelloschema=> SELECT * FROM organizations;

id |       name       |          description          |                label     

           |         created_at         |         updated_at         | task_id | sy

stem_info_keys

----+------------------+-------------------------------+---------------------------

-----------+----------------------------+----------------------------+---------+---

---------------

  8 | test-org-pt      | test purpose                  | test-org-pt              

           | 2012-11-16 09:13:07.483353 | 2012-11-16 09:13:07.483353 |         | --

- []


  1 | ACME_Corporation | ACME_Corporation Organization | ACME_Corporation         

           | 2012-11-14 08:57:53.75969  | 2012-11-28 07:15:24.235321 |      73 | --

- []


katelloschema=> DELETE FROM organizations WHERE name='ACME_Corporation';

DELETE 1

Expected results:
1. No scuh unexpected error.
2. The default org 'ACME_Corporation' should be deleted from Web GUI and DB successfully.

Additional info:

--- Additional comment from Lijun Li on 2012-11-29 01:19:43 EST ---

*** Bug 881569 has been marked as a duplicate of this bug. ***

--- Additional comment from Lijun Li on 2012-11-29 01:23:51 EST ---

Created attachment 654004 [details]
Unexpected error: Couldn't find Organization with ID=1

Comment 3 Marek Hulan 2012-12-12 09:18:36 UTC
I tried to reproduce this problem.

Steps:
1. Create a user and assign the default Organization 'ACME_Corporation' to it.
2. Administer -> Manage Organizations -> select 'ACME_Corporation' -> Remove organization - link is not active because I have to create another organization first
3. Create a new organization Testing
4. Repeat step 2, this time I got success 
 * "Organization 'ACME_Corporation' has been scheduled for background deletion."
 * "Successfully removed organization 'ACME_Corporation'."
5. Back to user name list, click on the user name that was assigned to the default Organization 'ACME_Corporation' in step 1, click on Environment sub tab I receive no error.

Could you please retest this bug and/or provide more precise steps to reproduce? Thank you.

Comment 4 Tom McKay 2012-12-12 14:45:30 UTC
confirmed works upstream

Comment 5 Tom McKay 2012-12-12 15:12:16 UTC
Re-opening...

I was able to reproduce: Create org zipco, assign to user, delete zipco, visit user... this worked. Re-created org zipco, visit user/environment, choose org/env, and save... error.

Could this be that an async job is running slow? Is org creation async?

Comment 6 Lukas Zapletal 2013-01-04 14:26:38 UTC
I prepared patch that removes default-scoped hiding of the organization beeing deleted and introduce new /nondefault/ scope without_deleting which is used in particular places:

UI:
 - list of organizations in the organization edit pane
 - list of organizations in the org selector
 - user edit page (default organization)

CLI/API:
 - list of orgs (api/organization_controller)
 - any action that accepts --org (api_controller#find_organization)

Once organization is deleted, all users who are working under this organization are automatically logged off (our permission layer redirect to the login page). They are no longer able to log in, even if the organization is still in the deletion process (but they can pick another organization from the list).

Although they is still (small) possibility logged user could submit a form using that organization. It would likely fail, but the plan is immediately log off all users with default or selected organization which is being deleted. We can't do this in this errata because this will need the change of how we store sessions in Katello.

Currently we are using cookie store which does not allow explicit deletion, I made two tasks for the next sprint to change this and add explicit sign-off for these users before org deletion is started (currently there is a TODO comment in the controller). This should prevent all possible errors.

Note to QA:

- create and delete org
- create org, stop katello-jobs, delete it, create another with the same label -> error should prevent the same label, start jobs, create again
- try various combinations of logged users (with the default org that gets deleted) while katello-jobs are stopped
- try to access the org via CLI/API which is scheduled for deletion while katello-jobs are stopped

All requests should hide the organization being deleted from the UI/CLI. Once katello-jobs is restarted, the org should be eventually deleted forever.

Comment 7 Lukas Zapletal 2013-01-11 17:20:10 UTC
The patch was finally merged upstream, please test accordingly as it completely change the way how we dealing with orgs being deleted: https://github.com/Katello/katello/pull/1358

Comment 8 Mike McCune 2013-09-19 18:12:40 UTC
These bugs have been resolved in upstream projects for a period of months so I'm mass-closing them as CLOSED:UPSTREAM.  If this is a mistake feel free to re-open.