Workable / flask-log-request-id

Flask extension to track and log Request-ID headers produced by PaaS like Heroku and load balancers like Amazon ELB
MIT License
113 stars 23 forks source link

self.app is NoneType bug in flask Application Factory Pattern #38

Closed karellincoln closed 5 years ago

karellincoln commented 5 years ago

environment

python 3.7, flask 1.02.Flask-Log-Request-ID==0.10.0

error

while I use Flask Application Factory Pattern:

request_id = RequestID()
def create_app(config_name=Config):
    app = Flask(__name__)
    app.config.from_object(config_name)
    celery.init_app(app=app)
    request_id.init_app(app)

meet the error

File "D:\学习知识\Python\microblog\app\__init__.py", line 24, in <module>
    request_id.init_app(app=app)
  File "C:\Users\z00453948\.virtualenvs\microblog\lib\site-packages\flask_log_request_id\request_id.py", line 84, in init_app
    if self.app.config['LOG_REQUEST_ID_LOG_ALL_REQUESTS']:
AttributeError: 'NoneType' object has no attribute 'config'

question

did I just change if self.app.config['LOG_REQUEST_ID_LOG_ALL_REQUESTS']: to if app.config['LOG_REQUEST_ID_LOG_ALL_REQUESTS']: to fix the error? Thank you!

halfdan commented 5 years ago

Currently running into the same issue. There's actually no reason to set self.app anywhere. init_app should use the app passed into it. There's no other use for self.app other than the one line that errors.

sque commented 5 years ago

This is the correct fix for the problem. Thanks for you time :) Unfortunately this was due to missing unit-tests for the case of lazy-initialization. We need to add extra tests for that case under https://github.com/Workable/flask-log-request-id/blob/develop/tests/request_id_tests.py before merging the branch

Sytten commented 5 years ago

Can this be merged now, it's kinda of annoying

ivica-k commented 4 years ago

I think this one should be reopened. If you download the archive for v0.10.1 and check line 84 in request_id.py you'll see that it still contains the self.app.config instead of app.config

Could be that CI somehow packaged the wrong commit/branch?

Sytten commented 4 years ago

I tried to simplify the process some months ago, but at the same time the dev didn't want to change a whole lot. I will add this to my todo to fix the branching and only use master.