Skip to content
Snippets Groups Projects
Commit 56179b2d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments][model] Fixed BlockInput backup/restore

Database hash doesn't exists anymore and rather than generating
natural keys that trigger the creation of get_by_natural_key
methods with way too many parameters, use tuples in tuples. This
make the code clearer to read as well as easier to maintain if the
natural key of a related field changes.
parent 784afe2e
No related branches found
No related tags found
2 merge requests!2551.4.x,!236Fix backup restore
...@@ -33,25 +33,26 @@ from ...databases.models import DatabaseSetOutput ...@@ -33,25 +33,26 @@ from ...databases.models import DatabaseSetOutput
from .block import Block from .block import Block
#---------------------------------------------------------- # ----------------------------------------------------------
class BlockInputManager(models.Manager): class BlockInputManager(models.Manager):
def get_by_natural_key(self, name, experiment_author, toolchain_author, def get_by_natural_key(self, block_natural_key,
toolchain_name, toolchain_version, experiment_name, cache_hash, database_natural_key):
cache_hash, database_hash): if block_natural_key:
block = Block.objects.get_by_natural_key(name, experiment_author, block = Block.objects.get_by_natural_key(*block_natural_key)
toolchain_author, toolchain_name, toolchain_version, else:
experiment_name) block = None
if cache_hash: if cache_hash:
return self.get(cache__hash=cache_hash, block=block) return self.get(cache__hash=cache_hash, block=block)
else: else:
return self.get(database__hash=database_hash, block=block) database = DatabaseSetOutput.objects.get_by_natural_key(
*database_natural_key)
return self.get(database=database, block=block)
#---------------------------------------------------------- # ----------------------------------------------------------
class BlockInput(models.Model): class BlockInput(models.Model):
...@@ -68,12 +69,16 @@ class BlockInput(models.Model): ...@@ -68,12 +69,16 @@ class BlockInput(models.Model):
null=True, on_delete=models.CASCADE) null=True, on_delete=models.CASCADE)
channel = models.CharField(max_length=200, default='', blank=True, channel = models.CharField(max_length=200, default='', blank=True,
help_text="Synchronization channel within the toolchain") help_text="Synchronization channel within "
"the toolchain")
objects = BlockInputManager() objects = BlockInputManager()
def natural_key(self): def natural_key(self):
if self.block:
block_natural_key = self.block.natural_key()
else:
block_natural_key = None
cache_hash = self.cache and self.cache.hash cache_hash = self.cache and self.cache.hash
database_hash = self.database and self.database.hash database_natural_key = self.database and self.database.natural_key()
return self.block.natural_key() + (cache_hash, database_hash) return (block_natural_key, cache_hash, database_natural_key)
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