Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

strange recursion error, when using Security() and later init_app() #317

Closed
wants to merge 2 commits into from

Conversation

joergwork
Copy link

One can't do something like:

my_security = Security()
and later on
my_security.init_app(app, ...)

'cause that ends in a strange recursion.
(Haven't tested that, but it should work. This was an issue on #pocoo from ianseyer)

One can't do something like:
my_security = Security 
and later on
my_security.init_app(...)

'cause that ends in a strange recursion. 
(Haven't tested that, but it should work)
@joergwork joergwork changed the title Update core.py strange recursion error, when using Security() and later init_app() Sep 25, 2014
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 65f74ca on joergwork:patch-1 into 76ad77a on mattupstate:develop.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 01045b0 on joergwork:patch-1 into 76ad77a on mattupstate:develop.

@hello-josh
Copy link

I ran into the same issue today because of self._state not being set. I can confirm that this fix works.

# Import the Flask Framework
from flask import Flask
from flask_security import Security
from flask_security_ndb import NDBUserDatastore, User, Role

# Flask app
app = Flask(__name__)

# Setup Flask-Security using the NDB adapter WIP
user_datastore = NDBUserDatastore(User, Role)
security_app = Security(datastore=user_datastore)

security_app.init_app(app)

# Override Flask-Mail for Google App Engine by 
# using the hook in :class:`flask_security.core._SecurityState`
security_app.send_mail_task(send_email)

@russomi
Copy link

russomi commented May 1, 2015

+1

@russomi
Copy link

russomi commented Oct 4, 2015

Any thoughts on this one? :neckbeard:


Reviewed 1 of 1 files at r2.
Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from the review on Reviewable.io

@davvid
Copy link

davvid commented Jan 2, 2016

I have a simpler fix in my fork that addresses this in a better way. We shouldn't set _state on the instance when using the deferred init_app() factory pattern. Instead, provide a default local proxy so that the existing getattr code works as-is. I'll open a new PR with that sug.

@jxltom
Copy link
Contributor

jxltom commented Feb 9, 2017

I have posted a example on how to initialize properly using factory method here in #194. The key is using state object returned by init_app instead of Security instance.

davvid added a commit to davvid/flask-security that referenced this pull request Jul 7, 2018
A previous bug caused infinite recursion when using the app-less
constructor with init_app().  Add tests to cover these use cases.

Related-to: pallets-eco#317
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants