Skip to content
Snippets Groups Projects
Commit 18706a6e authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: parents were added multiple times to created records

parent 3052a97b
No related branches found
No related tags found
1 merge request!53Release 0.1
......@@ -26,6 +26,7 @@
import os
import re
import caosdb as db
from .utils import has_parent
from .stores import GeneralStore, RecordStore
from .structure_elements import (StructureElement, Directory, File,
TextElement, DictTextElement, DictListElement)
......@@ -183,9 +184,11 @@ class Converter(object):
if "parents" in record:
for parent in record["parents"]:
c_record.add_parent(name=parent)
if not has_parent(c_record, parent):
c_record.add_parent(parent)
else:
c_record.add_parent(name=name)
if not has_parent(c_record, name):
c_record.add_parent(name)
for key, value in record.items():
if key == "parents":
......
#!/usr/bin/env python3
# encoding: utf-8
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Henrik tom Wörden
# 2021 Alexander Schlemmer
#
# 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
#
import caosdb as db
# Some utility functions, e.g. for extending pylib.
def has_parent(entity: db.Entity, name: str):
"""
A simple check, whether a parent with the given name exists.
There is a similar, however more complex function in package caosdb.
"""
for parent in entity.parents:
if parent.name == name:
return True
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment