Skip to content

Instantly share code, notes, and snippets.

View zzzeek's full-sized avatar
💭
SQLAlchemy 2.0 is released!

Michael Bayer zzzeek

💭
SQLAlchemy 2.0 is released!
View GitHub Profile
@zzzeek
zzzeek / test.py
Created September 20, 2016 22:57
pymysql failures w/ greenlets, sqla edition
import eventlet
eventlet.monkey_patch()
from sqlalchemy import exc
import itertools
import pymysql
import random
from eventlet.green import time
import greenlet
@zzzeek
zzzeek / test.py
Last active March 20, 2018 16:27
illustrate pymysql DB connection causing errors which resolve when we make sure they are recycled in greenletexit
import eventlet
eventlet.monkey_patch()
import itertools
import pymysql
import random
from eventlet.green import time
import greenlet
def connect():
@zzzeek
zzzeek / gist:8443477
Last active January 27, 2022 03:18
expands upon the SQLAlchemy "test rollback fixure" at http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#joining-a-session-into-an-external-transaction to also support tests that have any combination of ROLLBACK/COMMIT within them, by ensuring that the Session always runs transactions inside of a savepoint.
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
# a model
class Thing(Base):
__tablename__ = 'thing'
id = Column(Integer, primary_key=True)