From 1b29014af39e09c3cac6ca195dea617a854601bd Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Mon, 27 Apr 2020 20:10:50 -0700 Subject: [PATCH] Persist aggregate after persisting child entities --- src/protean/core/repository/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protean/core/repository/base.py b/src/protean/core/repository/base.py index c7cfed41..faf5fb78 100644 --- a/src/protean/core/repository/base.py +++ b/src/protean/core/repository/base.py @@ -112,12 +112,6 @@ def add(self, aggregate): # noqa: C901 logger.error(errors) raise ValidationError(errors) - # Persist only if the aggregate object is new, or it has changed since last persistence - if ((not aggregate.state_.is_persisted) or - (aggregate.state_.is_persisted and aggregate.state_.is_changed)): - dao = current_domain.get_dao(self.meta_.aggregate_cls) - dao.save(aggregate) - # If there are HasMany fields in the aggregate, sync child objects added/removed, # but not yet persisted to the database. # @@ -160,6 +154,12 @@ def add(self, aggregate): # noqa: C901 field.change = None field.change_old_value = None + # Persist only if the aggregate object is new, or it has changed since last persistence + if ((not aggregate.state_.is_persisted) or + (aggregate.state_.is_persisted and aggregate.state_.is_changed)): + dao = current_domain.get_dao(self.meta_.aggregate_cls) + dao.save(aggregate) + return aggregate def remove(self, aggregate):