diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dedd48931822c4c9b3c4a20e47410dbbc2b6acb..bd3c231b001cdd6eced03aa35bc15b2b0542f511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,5 +58,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed several bugs when an Entity inherits from itself (#18, caosdb-server #85). * Bug in `updateEntity.sql` (when updating the primary name without a prior call to `deleteEntityProperties`). Same thing for `deleteEntity`. +* #21 Bug which prevented deletion of deeply inheriting entities, if versioning was enabled. ### Security ### diff --git a/procedures/deleteIsaCache.sql b/procedures/deleteIsaCache.sql index f37c3fc8d4f7d7eeeff3ad651cf7b5ab0864d20f..c0fc831fb3482419a2c8215a06c693cdef16179c 100644 --- a/procedures/deleteIsaCache.sql +++ b/procedures/deleteIsaCache.sql @@ -29,7 +29,8 @@ DELIMITER // /* Delete "is a" relations from the given entity towards ancestors. -Note that relations towards descendants are not deleted (they probably should have been deleted before). +Note that relations towards descendants are not deleted (they probably should have been deleted +before). After this procedure, there are no more entries in `isa_cache`, where the parameter entity is a child or inside the rpath. @@ -54,7 +55,7 @@ BEGIN SELECT e.child, IVersion AS child_iversion, e.parent FROM isa_cache AS e WHERE e.child = EntityID - AND e.rpath = EntityID; + AND e.rpath = CAST(EntityID AS CHAR); END IF; DELETE FROM isa_cache diff --git a/tests/test_issues.sql b/tests/test_issues.sql new file mode 100644 index 0000000000000000000000000000000000000000..ab64de844e01c2ad3e273d6ea1e0c24709781a09 --- /dev/null +++ b/tests/test_issues.sql @@ -0,0 +1,64 @@ +/** + * ** header v3.0 + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * ** end header + */ + +USE _caosdb_schema_unit_tests; +BEGIN; +CALL tap.no_plan(); + + +-- ######################################################################## +-- TEST Issues from https://gitlab.com/caosdb/caosdb-mysqlbackend/-/issues +-- ######################################################################## + +------------------------------------------------------------------------------- +-- Issue 21 -- +-- Deleting a child with 3 levels of ancestors. -- +------------------------------------------------------------------------------- + +-- Setup +SET @SRID = "SRID_issue_21"; +INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES +(@SRID, 1234, 2345, "me", "home"); +CALL entityACL(@ACLID1, "{acl1}"); + +-- Insert entities and obtain IDs +CALL insertEntity("A", "Desc A", "RECORDTYPE", "{acl1}"); +CALL insertEntity("B", "Desc B", "RECORDTYPE", "{acl1}"); +CALL insertEntity("C", "Desc C", "RECORDTYPE", "{acl1}"); +CALL insertEntity("rec", "Desc rec", "RECORD", "{acl1}"); + +SELECT entity_id INTO @ID_A FROM name_data WHERE value="A"; +SELECT entity_id INTO @ID_B FROM name_data WHERE value="B"; +SELECT entity_id INTO @ID_C FROM name_data WHERE value="C"; +SELECT entity_id INTO @ID_rec FROM name_data WHERE value="rec"; + +-- Insert is-a relationships +CALL insertIsA(@ID_A, @ID_B); +CALL insertIsA(@ID_B, @ID_C); +CALL insertIsA(@ID_rec, @ID_A); + +-- Try to delete last child +-- leads to failure in issue #21 +CALL deleteIsa(@ID_rec); + +ROLLBACK;