Fixing incorrect license_error value in inventory_sync.

Signed-off-by: Yunfan Zhang <yz322@duke.edu>
This commit is contained in:
Yunfan Zhang
2018-08-02 14:19:13 -04:00
parent 95a9e1a7b6
commit 7001c67c84

View File

@@ -1005,6 +1005,9 @@ class Command(BaseCommand):
self.all_group.debug_tree() self.all_group.debug_tree()
with batch_role_ancestor_rebuilding(): with batch_role_ancestor_rebuilding():
# If using with transaction.atomic() with try ... catch,
# with transaction.atomic() must be inside the try section of the code as per Django docs
try:
# Ensure that this is managed as an atomic SQL transaction, # Ensure that this is managed as an atomic SQL transaction,
# and thus properly rolled back if there is an issue. # and thus properly rolled back if there is an issue.
with transaction.atomic(): with transaction.atomic():
@@ -1023,10 +1026,13 @@ class Command(BaseCommand):
if settings.SQL_DEBUG: if settings.SQL_DEBUG:
logger.warning('update computed fields took %d queries', logger.warning('update computed fields took %d queries',
len(connection.queries) - queries_before2) len(connection.queries) - queries_before2)
try: # Check if the license is valid.
# If the license is not valid, a CommandError will be thrown,
# and inventory update will be marked as invalid.
# with transaction.atomic() will roll back the changes.
self.check_license() self.check_license()
except CommandError as e: except CommandError as e:
self.mark_license_failure(save=True) self.mark_license_failure()
raise e raise e
if settings.SQL_DEBUG: if settings.SQL_DEBUG: