Bug #6481
closedAttributeError: '_AppCtxGlobals' object has no attribute 'identity'
100%
Description
We've got a traceback during handling of 404, it seems some attribute does not bubble through (or is not yet initialised). Authentication related maybe?
Message type: ERROR Location: /var/mentat/venv/lib/python3.7/site-packages/vial/app.py:168 Module: app Function: log_exception Time: 2020-08-26 01:31:32,094 Message: Exception on /static/design/vendor/cldr/main/cs/ca-gregorian.json? [GET] Traceback (most recent call last): File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/var/mentat/venv/lib/python3.7/site-packages/flask/helpers.py", line 1082, in send_static_file self.static_folder, filename, cache_timeout=cache_timeout File "/var/mentat/venv/lib/python3.7/site-packages/flask/helpers.py", line 767, in send_from_directory raise NotFound() werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 1815, in handle_user_exception return self.handle_http_exception(e) File "/var/mentat/venv/lib/python3.7/site-packages/flask/app.py", line 1743, in handle_http_exception return handler(e) File "/var/mentat/venv/lib/python3.7/site-packages/vial/app.py", line 394, in eh_page_not_found return vial.errors.error_handler_switch(404, err) File "/var/mentat/venv/lib/python3.7/site-packages/vial/errors.py", line 30, in error_handler_switch return error_response(status_code, exception = exc) File "/var/mentat/venv/lib/python3.7/site-packages/vial/errors.py", line 57, in error_response **payload File "/var/mentat/venv/lib/python3.7/site-packages/flask/templating.py", line 140, in render_template ctx.app, File "/var/mentat/venv/lib/python3.7/site-packages/flask/templating.py", line 120, in _render rv = template.render(context) File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render return original_render(self, *args, **kwargs) File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "/var/mentat/venv/lib/python3.7/site-packages/vial/blueprints/design_bs3/templates/http_error.html", line 1, in top-level template cod e {% extends "_layout.html" %} File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/environment.py", line 1005, in render return concat(self.root_render_func(self.new_context(vars))) File "/var/mentat/venv/lib/python3.7/site-packages/vial/blueprints/design_bs3/templates/http_error.html", line 14, in root {%- if exception and exception.description %} File "/var/mentat/venv/lib/python3.7/site-packages/vial/blueprints/design_bs3/templates/_layout.html", line 22, in root File "/var/mentat/venv/lib/python3.7/site-packages/vial/blueprints/design_bs3/templates/_layout.html", line 188, in block_body {%- endblock head %} File "/var/mentat/venv/lib/python3.7/site-packages/vial/blueprints/design_bs3/templates/http_error.html", line 93, in block_content File "/var/mentat/venv/lib/python3.7/site-packages/jinja2/runtime.py", line 262, in call return __obj(*args, **kwargs) File "/var/mentat/venv/lib/python3.7/site-packages/vial/app.py", line 829, in permission_can return vial.acl.PERMISSIONS[permission_name].can() File "/var/mentat/venv/lib/python3.7/site-packages/flask_principal.py", line 347, in can return self.require().can() File "/var/mentat/venv/lib/python3.7/site-packages/flask_principal.py", line 193, in can return self.identity.can(self.permission) File "/var/mentat/venv/lib/python3.7/site-packages/flask_principal.py", line 188, in identity return g.identity File "/var/mentat/venv/lib/python3.7/site-packages/werkzeug/local.py", line 348, in __getattr__ return getattr(self._get_current_object(), name) AttributeError: '_AppCtxGlobals' object has no attribute 'identity'
Related issues
Updated by Rajmund Hruška about 4 years ago
Pavel Kácha wrote:
We've got a traceback during handling of 404, it seems some attribute does not bubble through (or is not yet initialised). Authentication related maybe?
[...]
There are /static/<path:filename> and /static/design/<path:filename> routes set in Flask. Module Flask Principal is initialized with skip_static = True
. Because of that, the saving of identity is skipped. A quick and easy fix would be to set skip_static
to True
.
Updated by Pavel Kácha about 4 years ago
- Assignee changed from Rajmund Hruška to Jan Mach
Mek, from the top of your head, are there any static routes through Flask used? (I mean actual reason to allow static contents served through Flask.)
Updated by Jan Mach about 4 years ago
Static paths are used to serve resources like images (log, flags) or library files (jQuery, ...). They are intentionally set to be skipped by authentication, there is no point in preventing someone download the logo image. However since they are served by flask, built-in error handling process kicks in in case file is not found. Logging is attempted and it crashes on attempting to get the identity of the user. In normal circumstances there is always an user object, either anonymous, or authenticated. I would need to research this more, but the best solution would be first to try to skip the dumping of user object for logging in case it is not set and then fix the library path issue. Original error is the library JS file missing for some reason: /static/design/vendor/cldr/main/cs/ca-gregorian.json.
Updated by Rajmund Hruška about 4 years ago
I wrote a code to skip the check of permissions and it seems to be working. It seems I don't have a permission to write to this repository yet.
Regarding the original 404 error, the correct path to the requested file is /static/vendor/cldr/main/en/ca-gregorian.json. My console log at Chromium browser says that the file was loaded. I don't know why there was a 'design' in the path.
Updated by Rajmund Hruška about 4 years ago
The changes I made are available in my branch hruska-bugfix-#6481-identity.
Updated by Rajmund Hruška about 4 years ago
- Status changed from New to In Progress
Updated by Jan Mach about 4 years ago
- Status changed from In Progress to Feedback
- Assignee changed from Jan Mach to Pavel Kácha
- Target version changed from Backlog to 2.7
- % Done changed from 0 to 100
Hi, I have reviewed the proposed fix and it look good to me. I have just performed merge, built and deployed packages to mentat-alt. Good job, Rajmund.
As to the 404 error for /static/design/vendor/cldr/main/cs/ca-gregorian.json? [GET], it is a mystery to me as well. I have walked through the code and was not able to find origin from where it could come. Some time ago some design specific static files were part of the design_bs3
blueprint. Due to the static_url_path = '/static/design'
configuration this URL was then correct. For certain reason these static files were moved to application`s static folder and all references to 'design.static' have been changed to 'static'.
I was not able to find where did the request for '/static/design/' URL come from.
In the web server log file I have found the following:
66.249.79.217 - - [26/Aug/2020:01:36:32 +0200] "GET /mentat/static/design/vendor/cldr/main/cs/units.json HTTP/1.1" 500 7933 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
I would guess Google was checking and updating his cached indices.
Updated by Jan Mach about 4 years ago
Deployed to mentat-hub. Everything seems to be in order and working.
Updated by Rajmund Hruška about 2 months ago
- Related to Bug #7781: Identity error on /static/* added