Maximum recursion depth exceeded
See original GitHub issueIf the security
object gets initialized before the app
exists (i.e. using the factory method) and init_app
is called later, security._state
is never set. This makes sense because _state
is dependent upon the app
, however, when an attribute on security
is accessed, the redefinition of __getattr__
looks for _state
, which isn’t set, so __getattr__
get’s called, looks for _state
, etc, and then bam
RuntimeError: maximum recursion depth exceeded while calling a Python object
I opened a PR, but closed it because I’m not sure if it’s the right fix. I solved the issue myself by doing:
security = app.extensions['security']
@security.login_context_processor
...
but at the very least, I think there should be a better exception that gets raised (the max recursion depth really threw me off for a bit.) The solution in the PR would work, but would require the above to become something like
with app.app_context():
@security.login_context_processor
...
which maybe works? Curious what other people think is a good solution.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:5
- Comments:15 (3 by maintainers)
I have searched for the old issues and found that the author has explained here and here in #141 that the constructor and
init_app
are not meant to be used together. This is for initialize many applications with sameSecurity
instance. So this may not be a bug or just addingself._state = None
as followings can fixing this issue.@diginikkari The proper way for initialize is that accessing attributes by
getattr
is OK when using constructors. But when using factory method, users need to access security attributes bystate
object which is returned byinit_app
. Here is an example on how to initialize using factory method. This example is for accessingsend_mail_task
, but you can use it for other attributes such aslogin_context_processor
as well. I have posted a more detailed example on how to use Celey async task assend_mail_task
using factory method here.As @eriktaubeneck and @diginikkari said, Flask-Social now dont support flask factory pattern. Also there is manual for it.
As I see some people try to fix it partially: #471, #465, #384(I ask @Diaoul if he want to fix failing tests or not. If not, I add this part to my solution.), #317 Also I start implement proper solution in my branch, pls review code and give me feedback. State of work:
[Update 1] Old test: it was my setup problem, now tests fail only for py33, some _ssl3 stuff, w8 for package update. [Update 2] Old test: yes, it was problem in py33 compilation. Now all test pass. [Update 3] PM #495