Skip to content
Snippets Groups Projects
Commit 94a3c46b authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: use update arguments in guard

parent 8c3897ce
No related branches found
No related tags found
1 merge request!22Release 0.3
...@@ -491,7 +491,7 @@ carefully and if the changes are ok, click on the following link: ...@@ -491,7 +491,7 @@ carefully and if the changes are ok, click on the following link:
logger.debug(cfood.to_be_updated) logger.debug(cfood.to_be_updated)
try: try:
guard.safe_update(cfood.to_be_updated) guard.safe_update(cfood.to_be_updated, unique=False)
except ProhibitedException: except ProhibitedException:
self.update_cache.insert(cfood.to_be_updated, self.run_id) self.update_cache.insert(cfood.to_be_updated, self.run_id)
except Exception as e: except Exception as e:
...@@ -539,7 +539,7 @@ carefully and if the changes are ok, click on the following link: ...@@ -539,7 +539,7 @@ carefully and if the changes are ok, click on the following link:
logger.debug("No new entities to be inserted.") logger.debug("No new entities to be inserted.")
else: else:
try: try:
guard.safe_insert(missing_identifiables) guard.safe_insert(missing_identifiables, unique=False)
except Exception as e: except Exception as e:
DataModelProblems.evaluate_exception(e) DataModelProblems.evaluate_exception(e)
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
import caosdb as db import caosdb as db
RETRIEVE = 0 RETRIEVE = 0
INSERT = 1 INSERT = 1
UPDATE = 2 UPDATE = 2
...@@ -36,10 +35,10 @@ class Guard(object): ...@@ -36,10 +35,10 @@ class Guard(object):
self.freshly_created = [] self.freshly_created = []
self.level = level self.level = level
def safe_insert(self, obj): def safe_insert(self, obj, *args, **kwargs):
if self.level < INSERT: if self.level < INSERT:
raise ProhibitedException("not allowed") raise ProhibitedException("not allowed")
obj.insert() obj.insert(*args, **kwargs)
if isinstance(obj, db.Container): if isinstance(obj, db.Container):
self.freshly_created.extend([ self.freshly_created.extend([
...@@ -47,7 +46,7 @@ class Guard(object): ...@@ -47,7 +46,7 @@ class Guard(object):
else: else:
self.freshly_created.append(obj.id) self.freshly_created.append(obj.id)
def safe_update(self, obj, **kwargs): def safe_update(self, obj, *args, **kwargs):
if isinstance(obj, db.Container): if isinstance(obj, db.Container):
all_fresh = True all_fresh = True
...@@ -58,12 +57,12 @@ class Guard(object): ...@@ -58,12 +57,12 @@ class Guard(object):
if self.level < UPDATE and not all_fresh: if self.level < UPDATE and not all_fresh:
raise ProhibitedException("not allowed") raise ProhibitedException("not allowed")
else: else:
obj.update(**kwargs) obj.update(*args, **kwargs)
else: else:
if self.level < UPDATE and obj.id not in self.freshly_created: if self.level < UPDATE and obj.id not in self.freshly_created:
raise ProhibitedException("not allowed") raise ProhibitedException("not allowed")
else: else:
obj.update(**kwargs) obj.update(*args, **kwargs)
def set_level(self, level): def set_level(self, level):
self.level = level self.level = level
......
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