@@ -14,12 +14,11 @@ def initialize():
14
14
# pylint: disable=E1101
15
15
django .setup ()
16
16
initialize ()
17
+ from django .conf import settings
17
18
from acme_srv .models import Account , Authorization , Cahandler , Certificate , Challenge , Housekeeping , Nonce , Order , Status
18
-
19
19
from django .db import transaction
20
20
# from acme_srv.monkey_patches import django_sqlite_atomic
21
- import acme_srv .monkey_patches
22
-
21
+ import acme_srv .monkey_patches
23
22
24
23
class DBstore (object ):
25
24
""" helper to do datebase operations """
@@ -138,9 +137,14 @@ def authorization_update(self, data_dic):
138
137
if 'status' in data_dic :
139
138
data_dic ['status' ] = self ._status_getinstance (data_dic ['status' ], 'name' )
140
139
141
- with transaction . atomic ( immediate = True ) :
140
+ if settings . DATABASES [ 'default' ][ 'ENGINE' ] == 'django.db.backends.sqlite3' :
142
141
self .logger .debug ('DBStore.authorization_update(): patching transaction to transform all atomic blocks into immediate transactions' )
143
- # add authorization
142
+ with transaction .atomic (immediate = True ):
143
+ # update authorization
144
+ obj , _created = Authorization .objects .update_or_create (name = data_dic ['name' ], defaults = data_dic )
145
+ obj .save ()
146
+ else :
147
+ # update authorization
144
148
obj , _created = Authorization .objects .update_or_create (name = data_dic ['name' ], defaults = data_dic )
145
149
obj .save ()
146
150
@@ -180,8 +184,12 @@ def challenge_add(self, value, mtype, data_dic):
180
184
# replace orderstatus with an instance
181
185
data_dic ['status' ] = self ._status_getinstance (data_dic ['status' ])
182
186
183
- with transaction . atomic ( immediate = True ) :
187
+ if settings . DATABASES [ 'default' ][ 'ENGINE' ] == 'django.db.backends.sqlite3' :
184
188
self .logger .debug ('DBStore.challenge_add(): patching transaction to transform all atomic blocks into immediate transactions' )
189
+ with transaction .atomic (immediate = True ):
190
+ obj , _created = Challenge .objects .update_or_create (name = data_dic ['name' ], defaults = data_dic )
191
+ obj .save ()
192
+ else :
185
193
obj , _created = Challenge .objects .update_or_create (name = data_dic ['name' ], defaults = data_dic )
186
194
obj .save ()
187
195
0 commit comments