Giter Club home page Giter Club logo

cherrypy-sqlalchemy's People

Contributors

ionrock avatar karlinnolabs avatar phwoelfel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cherrypy-sqlalchemy's Issues

MySQL server has gone away error crashes web app

So my MySQL server reboots once in a while and when it does so I get the above error message, after that sqlalchemy can no longer connect and repeatedly says

"InvalidRequestError: Can't reconnect until invalid transaction is rolled back"

Is there a way to catch this issue, roll back the transaction and reconnect with cherrypy-sqlalchemy?

Trouble using in pytests

I am trying to use this in my pytests but I am getting error

AttributeError: type object 'Base' has no attribute 'metadata'

My code is

class Base:

    def get_session(self):
        cherrypy.tools.db = SQLAlchemyTool()

        db_uri = 'postgresql://{0}:{1}@{2}:{3}/{4}'.format(
            settings['database']['user'],
            settings['database']['password'],
            settings['database']['host'],
            settings['database']['port'],
            settings['database']['dbname']
        )
        sqlalchemy_plugin = SQLAlchemyPlugin(
            cherrypy.engine, Base, db_uri,
            echo=True
        )
        sqlalchemy_plugin.subscribe()
        sqlalchemy_plugin.bind_db()

        engine = create_engine(db_uri)
        Session = sessionmaker(bind=engine)
        return Session()

and when I try to use this

class TestAuditModel(Base):

    @property
    def get_db(self):
        return cherrypy.request.db

    def test_insert(self):
        db = self.get_session() # On this line I get issues 
        test = Test(starttime=datetime.now(),
                      endtime=datetime.now(),
                      count=1)

Now I had written this file after looking at the module files

class SQLAlchemyPlugin(plugins.SimplePlugin):
    def __init__(self, bus, orm_base, db_uri, **kwargs):
        """
        The plugin is registered to the CherryPy engine and therefore
        is part of the bus (the engine *is* a bus) registery.

        We use this plugin to create the SA engine. At the same time,
        when the plugin starts we create the tables into the database
        using the mapped class of the global metadata.

        Finally we create a new 'bind' channel that the SA tool
        will use to map a session to the SA engine at request time.
        """
        plugins.SimplePlugin.__init__(self, bus)
        self.db_uri = db_uri
        self.orm_base = orm_base
        self.create_kwargs = kwargs

        self.bus.subscribe('db.start_session', self.start_session)
        self.bus.subscribe('db.bind_db', self.bind_db)

        self.sa_engine = None

    def start(self):
        self.sa_engine = create_engine(self.db_uri)

    def bind_db(self):
        if not self.sa_engine:
            self.start()
        self.orm_base.metadata.bind = self.sa_engine # (here I get the error

    def stop(self):
        if self.sa_engine:
            self.sa_engine.dispose()
            self.sa_engine = None

    def start_session(self, session):
        session.configure(bind=self.sa_engine)

    def execute(self):
        return create_engine(self.db_uri).connect()

pypi release

0.5.1 has a connection close bug which I fixed and you merged but the pypi release is out of date. We found that 0.5.1 was leaving 250+ connections to the DB open, with 0.5.2 these connections go away.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.