espeed/bulbs — Issue #19: Change Graph constructor defaults
Author: reydelamirienda
Created: 2011-12-17 14:18:47+00:00
State: open

I guess that with the new Configuration object in 0.3 this bug may be obsolete, but anyway:

Graph takes a constructor parameter db_url that has config.DATABASE_URL as default value. This causes problems because default parameters in python are evaluated when importing for the first time, and never again. If config.DATABASE_URL changes, the constructor will keep using the old value. This is a feature from python.

To solve this, change the constructor like this:

def __init__(self, db_url=None):
self.db_url = db_url if db_url else config.DATABASE_URL

This way, config.DATABASE_URL will be evaluated for every constructor call