Issue #17 new

Alternative setup does not work

created an issue

The documentation says:

mail = Mail()

app = Flask(__name__)

However, if you try to use this mail object you'll end up with an infinite recursion error, because unlike in its __init__ method, init_app does not set the state. It returns it! Allow me to demonstrate:

from flask import Flask
from flask.ext.mail import Mail

mail = Mail()
app = Flask(__name__)
state = mail.init_app(app)


    print "Mail server is: ", mail.server
except RuntimeError, error:
    print error

print "setting state."
mail.state = state
print "Mail server is: ", mail.server

So either Mail.init_app needs to be changed, so it sets the state, or the documentation for this part needs to change to:

mail = Mail()

app = Flask(__name__)
mail.state = mail.init_app(app)

Preferably the former, but this is the work-around I'm using for now.

Comments (1)

  1. Log in to comment