MCPcopy
hub / github.com/django/django / asave

Method asave

django/contrib/sessions/backends/db.py:139–167  ·  view source on GitHub ↗

See save().

(self, must_create=False)

Source from the content-addressed store, hash-verified

137 raise
138
139 async def asave(self, must_create=False):
140 """See save()."""
141 if self.session_key is None:
142 return await self.acreate()
143 data = await self._aget_session(no_load=must_create)
144 obj = await self.acreate_model_instance(data)
145 using = router.db_for_write(self.model, instance=obj)
146 try:
147 # This code MOST run in a transaction, so it requires
148 # @sync_to_async wrapping until transaction.atomic() supports
149 # async.
150 @sync_to_async
151 def sync_transaction():
152 with transaction.atomic(using=using):
153 obj.save(
154 force_insert=must_create,
155 force_update=not must_create,
156 using=using,
157 )
158
159 await sync_transaction()
160 except IntegrityError:
161 if must_create:
162 raise CreateError
163 raise
164 except DatabaseError:
165 if not must_create:
166 raise UpdateError
167 raise
168
169 def delete(self, session_key=None):
170 if session_key is None:

Callers 4

acreateMethod · 0.95
asessionMethod · 0.95
_acreate_userMethod · 0.45
setterMethod · 0.45

Calls 4

acreateMethod · 0.95
_aget_sessionMethod · 0.80
db_for_writeMethod · 0.45

Tested by

no test coverage detected