Skip to content

Commit

Permalink
Revert "when updating, using session merge from a copy model instance…
Browse files Browse the repository at this point in the history
… to make sure sqla before/after update listener is only called once"

This reverts commit c69412684368e6aadfc456a5c7100df33a03e3d2.
  • Loading branch information
zef committed Aug 24, 2023
1 parent 7827767 commit 225be2b
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions superset/daos/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,8 @@ def update(
setattr(item, key, value)

try:
db.session.add(instance_model)
if commit:
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback()
raise DAOCreateFailedError(exception=ex) from ex
db.session.merge(item)

@classmethod
def update(cls, model: T, properties: dict[str, Any], commit: bool = True) -> T:
"""
Generic update a model
:raises: DAOCreateFailedError
"""
d = dict(model.__dict__)
d.pop("_sa_instance_state") # get rid of SQLAlchemy special attr
copy = model.__class__(**d)
copy.id = model.id
# create a copy of the model here
# so it doesn't trigger before_update/after_update sqla listener each time
# we set a property
for key, value in properties.items():
setattr(copy, key, value)
try:
db.session.merge(copy)
if commit:
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
Expand Down

0 comments on commit 225be2b

Please sign in to comment.