Skip to content

Instantly share code, notes, and snippets.

View npilon's full-sized avatar

Nicholas Pilon npilon

View GitHub Profile
from sqlalchemy import Column, ForeignKey, Integer, and_, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
backref, foreign, relationship, scoped_session, sessionmaker
)
Base = declarative_base()
@npilon
npilon / minimal_eager_chain.py
Last active March 6, 2018 20:53
Demonstrate over-aggressive synchronous subtask check in eager application
"""Celery master is too aggressive about suppressing .get() in eager tasks.
test performs no synchronous operations, but fails in eager application::
python minimal_eager_chain.py shell --config=minimal_eager_chain
test.delay().get()
"""
import celery
from celery.canvas import chord
@npilon
npilon / minimal_chord_chain.py
Created March 6, 2018 19:37
Demonstrate inconsistent behavior of celery.canvas.chord in celery 4.1.0
"""Demonstrate inconsistent chord header result values:
Run by::
pip install celery redis
python minimal_chord_chain.py worker --loglevel INFO --config=minimal_chord_chain
# Separate shell
python minimal_chord_chain.py shell --config=minimal_chord_chain
@npilon
npilon / minimal_pickle.py
Last active March 2, 2018 21:44
A minimal example demonstrating how SQLAlchemy 1.2 breaks pickling of ORM objects
"""Demonstrate how SQLAlchemy 1.2 breaks pickling of ORM objects.
This somewhat-contrived example shows a query scenario where:
- We have an object (Garply)
- It is related to a table of Foos
- Foos uses single-table polymorphism to hold multiple types
- We query a Garply and eager-load some of its Foos
- We then pickle this Garply and its Foos for hand-off to some other process.
Since it already has its Foos loaded, we know it won't need further database

Keybase proof

I hereby claim:

  • I am npilon on github.
  • I am npilon (https://keybase.io/npilon) on keybase.
  • I have a public key ASBiU6E2WYyVG4ICh2hQ-W7FIYECSYRbRoRTEppEIeHRLAo

To claim this, I am signing this object:

@npilon
npilon / calling.py
Last active August 29, 2015 14:15
Examples of python calling conventions.
def foo(a, b, c):
print 'a', a
print 'b', b
print 'c', c
foo(1, 2, 3)
foo(a=1, b=2, c=3)
foo(c=1, a=3, b=2)
foo(1, b=2, c=3)