File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change 14
14
import sqlalchemy .orm .exc
15
15
import sqlalchemy_utils
16
16
import structlog
17
- from sqlalchemy .dialects .postgresql import JSONB
17
+ from sqlalchemy .dialects .postgresql import JSONB , insert
18
18
from typing_extensions import Iterable
19
19
20
20
import alembic .command
@@ -804,19 +804,15 @@ def ensure_adaptor_properties(
804
804
session : sa .orm .Session ,
805
805
) -> None :
806
806
"""Create adaptor properties (if not exists) or update its timestamp."""
807
- try :
808
- adaptor_properties = AdaptorProperties (hash = hash , config = config , form = form )
809
- session .add (adaptor_properties )
810
- session .commit ()
811
- except sa .exc .IntegrityError : # hash already present
812
- session .rollback ()
813
- statement = (
814
- AdaptorProperties .__table__ .update ()
815
- .where (AdaptorProperties .__table__ .c .hash == hash )
816
- .values (timestamp = datetime .datetime .now ())
817
- )
818
- session .execute (statement )
819
- session .commit ()
807
+ insert_stmt = insert (AdaptorProperties .__table__ ).values (
808
+ hash = hash , config = config , form = form
809
+ )
810
+ do_update_stmt = insert_stmt .on_conflict_do_update (
811
+ constraint = "adaptor_properties_pkey" ,
812
+ set_ = dict (timestamp = datetime .datetime .now ()),
813
+ )
814
+ session .execute (do_update_stmt )
815
+ session .commit ()
820
816
821
817
822
818
def add_event (
You can’t perform that action at this time.
0 commit comments