question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A replacement for playhouse.shortcuts.RetryOperationalError?

See original GitHub issue

Commit 54a672547f549eb381cd9578a2b19310bcf5ef1d removed the class playhouse.shortcuts.RetryOperationalError. Is there a new recommended way to automatically reconnect and retry on failed queries?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
gzxultracommented, Feb 26, 2018

This should work if you have legacy code.

from peewee import MySQLDatabase
from peewee import OperationalError


class RetryOperationalError(object):

    def execute_sql(self, sql, params=None, commit=True):
        try:
            cursor = super(RetryOperationalError, self).execute_sql(
                sql, params, commit)
        except OperationalError:
            if not self.is_closed():
                self.close()
            with __exception_wrapper__:
                cursor = self.cursor()
                cursor.execute(sql, params or ())
                if commit and not self.in_transaction():
                    self.commit()
        return cursor


class MyRetryDB(RetryOperationalError, MySQLDatabase):
    pass

3reactions
coleifercommented, Sep 29, 2018

Small note:

__exception_wrapper__ should not have parentheses afterwards – you don’t need to call it. I went ahead and edited your code snippet to make the change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playhouse, extensions to Peewee
The replace function returns a new JSON string formed by updating the input JSON with the given path/value pairs. If the path does...
Read more >
python - How can I use peewee db_url.connect() to generate a ...
My solution is hacking the db_url.schemes class MySQLRetryDB(RetryOperationalError, PooledMySQLDatabase): pass schemes['mysql+pool+retry'] ...
Read more >
311devs-peewee Changelog - PyUp.io
The main change in this release is the removal of the `AESEncryptedField`, which was included as part of the `playhouse.fields` extension. It was...
Read more >
peewee Documentation [image] - manpages.ubuntu!
Usage: from peewee import * from playhouse.shortcuts import RetryOperationalError class MyRetryDB(RetryOperationalError, MySQLDatabase): pass db ...
Read more >
peewee Documentation - Read the Docs
statements are typically run against a new database connection. ... from playhouse.shortcuts import RetryOperationalError.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found