Skip to content

Commit 576ec8b

Browse files
committed
bugfix: ensure_adaptor_properties without rare integrity errors
1 parent d6de023 commit 576ec8b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cads_broker/database.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,18 @@ def ensure_adaptor_properties(
715715
) -> None:
716716
"""Create adaptor properties (if not exists) or update its timestamp."""
717717
try:
718+
adaptor_properties = AdaptorProperties(hash=hash, config=config, form=form)
719+
session.add(adaptor_properties)
720+
session.commit()
721+
except sa.exc.IntegrityError: # hash already present
722+
session.rollback()
718723
statement = (
719724
AdaptorProperties.__table__.update()
720-
.returning(AdaptorProperties.hash)
721725
.where(AdaptorProperties.__table__.c.hash == hash)
722726
.values(timestamp=datetime.datetime.now())
723727
)
724-
session.execute(statement).one()
725-
except sqlalchemy.orm.exc.NoResultFound:
726-
adaptor_properties = AdaptorProperties(hash=hash, config=config, form=form)
727-
session.add(adaptor_properties)
728+
session.execute(statement)
729+
session.commit()
728730

729731

730732
def add_event(

0 commit comments

Comments
 (0)