Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit logs before rollback() #3125

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/pbench/server/database/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,14 @@ def advance(self, new_state: States):
raise DatasetBadParameterType(new_state, States)
elif new_state not in self.transitions[self.state]:
self.logger.error(
"Current state {} can't advance to {}", self.state, new_state
"{}, Current state {} can't advance to {}", self, self.state, new_state
)
raise DatasetBadStateTransition(self, new_state)

# TODO: this would be a good place to generate an audit log
self.logger.debug(
"{}, Current state {}, advancing to {}", self, self.state, new_state
)

self.state = new_state
self.transition = datetime.datetime.utcnow()
Expand All @@ -648,12 +651,12 @@ def add(self):
Database.db_session.add(self)
Database.db_session.commit()
except IntegrityError as e:
Dataset.logger.warning("Duplicate dataset {}: {}", self.name, e)
Database.db_session.rollback()
self.logger.warning("Duplicate dataset {}: {}", self.name, e)
raise DatasetDuplicate(self.name) from None
except Exception:
self.logger.exception("Can't add {} to DB", str(self))
Database.db_session.rollback()
self.logger.exception("Can't add {} to DB", str(self))
raise DatasetSqlError("adding", name=self.name)

def update(self):
Expand All @@ -664,8 +667,8 @@ def update(self):
try:
Database.db_session.commit()
except Exception:
self.logger.error("Can't update {} in DB", str(self))
Database.db_session.rollback()
self.logger.error("Can't update {} in DB", str(self))
raise DatasetSqlError("updating", name=self.name)

def delete(self):
Expand Down Expand Up @@ -1201,8 +1204,8 @@ def add(self, dataset: Dataset):
Database.db_session.add(self)
Database.db_session.commit()
except Exception as e:
Metadata.logger.exception("Can't add {}>>{} to DB", dataset, self.key)
Database.db_session.rollback()
self.logger.exception("Can't add {}>>{} to DB", dataset, self.key)
dataset.metadatas.remove(self)
raise MetadataSqlError("adding", dataset, self.key) from e

Expand All @@ -1213,8 +1216,8 @@ def update(self):
try:
Database.db_session.commit()
except Exception as e:
Metadata.logger.exception("Can't update {} in DB", self)
Database.db_session.rollback()
self.logger.exception("Can't update {} in DB", self)
raise MetadataSqlError("updating", self.dataset, self.key) from e

def delete(self):
Expand All @@ -1225,8 +1228,8 @@ def delete(self):
Database.db_session.delete(self)
Database.db_session.commit()
except Exception as e:
Metadata.logger.exception("Can't delete {} from DB", self)
Database.db_session.rollback()
self.logger.exception("Can't delete {} from DB", self)
raise MetadataSqlError("deleting", self.dataset, self.key) from e


Expand Down