Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code to handle mysql transactions atomically for Topic/Forum ReadTracker broken of postgresql with read replicas #291

Open
siovene opened this issue Mar 5, 2020 · 0 comments

Comments

@siovene
Copy link
Contributor

siovene commented Mar 5, 2020

In models.py, you have some code to attempt a transaction to create a TopicReadTracker or ForumReadTracker, and rollback if it fails.

The comment mentions that it's a workaround because get_or_create can fail on MySQL.

I have been running pybbm for a few years on PostgreSQL and when I configured my cluster to have read replicas, I ran into this problem:

File "/src/pybbm/pybb/views.py" in mark_read
  385.             topic_mark, new = TopicReadTracker.objects.get_or_create_tracker(topic=self.topic, user=self.request.user)

File "/src/pybbm/pybb/models.py" in get_or_create_tracker
  423.             transaction.savepoint_commit(sid)

File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py" in savepoint_commit
  74.     get_connection(using).savepoint_commit(sid)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in savepoint_commit
  363.         self._savepoint_commit(sid)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py" in _savepoint_commit
  312.             cursor.execute(self.ops.savepoint_commit_sql(sid))

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/operations.py" in savepoint_commit_sql
  355.         return "RELEASE SAVEPOINT %s" % self.quote_name(sid)

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/operations.py" in quote_name
  111.         if name.startswith('"') and name.endswith('"'):

Exception Type: AttributeError at /forum/c/astrobin/annoucements/db-upgrade-coming-soon-thank-you-for-your-patience/
Exception Value: 'NoneType' object has no attribute 'startswith'

To solve it, you can only do the transaction "trick" if 'mysql' in connection.vendor (where connection is imported from django.db). For other engines, just fallback to the regular get_or_create of the manager's super class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant