Save the current session data to the database. If 'must_create' is True, raise a database error if the saving operation doesn't create a new entry (as opposed to possibly updating an existing entry).
(self, must_create=False)
| 112 | ) |
| 113 | |
| 114 | def save(self, must_create=False): |
| 115 | """ |
| 116 | Save the current session data to the database. If 'must_create' is |
| 117 | True, raise a database error if the saving operation doesn't create a |
| 118 | new entry (as opposed to possibly updating an existing entry). |
| 119 | """ |
| 120 | if self.session_key is None: |
| 121 | return self.create() |
| 122 | data = self._get_session(no_load=must_create) |
| 123 | obj = self.create_model_instance(data) |
| 124 | using = router.db_for_write(self.model, instance=obj) |
| 125 | try: |
| 126 | with transaction.atomic(using=using): |
| 127 | obj.save( |
| 128 | force_insert=must_create, force_update=not must_create, using=using |
| 129 | ) |
| 130 | except IntegrityError: |
| 131 | if must_create: |
| 132 | raise CreateError |
| 133 | raise |
| 134 | except DatabaseError: |
| 135 | if not must_create: |
| 136 | raise UpdateError |
| 137 | raise |
| 138 | |
| 139 | async def asave(self, must_create=False): |
| 140 | """See save().""" |
no test coverage detected