Monday, December 13, 2021

update_or_create: OperationalErrorr "Savepoint doesn't exist" update_or_create

Hello Django Community,
    (MySQL 5.7.35 + Django 3.2.9)
    I got this following error when trying to use update_or_create function to update or create data of a model. It only breaks if there is no matched data in the database, but despite this error, the data still gets created. Can anyone help me with this bug? Thanks a lot!

(Dumped error message here)
Traceback (most recent call last):
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/models/query.py", line 581, in get_or_create
    return self.get(**kwargs), False
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/models/query.py", line 437, in get
    self.model._meta.object_name
feather.models.File.DoesNotExist: File matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1305, 'SAVEPOINT s140190368511744_x1 does not exist')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/app/views/projects.py", line 159, in project_files
    pm.add_file(tp_file, tp_file_content)
  File "/home/app/helpers.py", line 223, in add_file
    defaults=dict(updated_at=datetime.now()),
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/models/query.py", line 608, in update_or_create
    obj, created = self.select_for_update().get_or_create(defaults, **kwargs)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/models/query.py", line 588, in get_or_create
    return self.create(**params), True
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/transaction.py", line 230, in __exit__
    connection.savepoint_commit(sid)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 368, in savepoint_commit
    self._savepoint_commit(sid)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 314, in _savepoint_commit
    cursor.execute(self.ops.savepoint_commit_sql(sid))
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/usr/local/anaconda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/anaconda/lib/python3.7/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1305, 'SAVEPOINT s140190368511744_x1 does not exist')

Confidentiality Notice: The information contained herein is for informational purposes only. This message is private and the information contained in this message, including any attachments, contains information that may be confidential, privileged and/or proprietary. It is intended to be read only by the individual or entity to whom it is addressed. If you are not the intended recipient, please notify the sender by replying to this message, delete the material immediately from your system and note that you must not review, disclose, copy, distribute or take any action in reliance on or in reference to this message, including any attachments.  No confidentiality, privilege, or property rights are waived or lost by any errors in transmission. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a49da1d0-b5a3-42ff-a1cb-c62d733265afn%40googlegroups.com.

No comments:

Post a Comment